The v-tab-item content is not loading properly when the component is initialized in the mounted hook

I'm working on a project that utilizes Vuetify tabs to showcase two different components under separate tabs. The problem I'm encountering is that, within the mounted() function, when attempting to access the refs of the components, only the ref of the first component (details) appears and the general refs are not visible. Any assistance in identifying my mistake would be greatly appreciated.

To troubleshoot, I've added a debugger in the mounted() function and found that only the details refs show up when using this.$refs.

<template>
      <div>    
        <v-tabs slot="extension"
                v-model="tab_title"
                centered
                color="black"
                slider-color="red">
          <v-tab  key="details" href="#tab-details">Details</v-tab>
          <v-tab  key="general" href="#tab-general">General</v-tab>    
        </v-tabs>
        <v-tabs-items touchless v-model="tab_title">
          <v-tab-item key="details" value="tab-details">
            <v-card flat>
              <Details ref="details_form"></Details>
            </v-card>
          </v-tab-item>
          <v-tab-item key="general" value="tab-general">
            <v-card flat>
              <Info ref="general_form" :agent="agent"></Info>
            </v-card>
          </v-tab-item>
        </v-tabs-items>
      </div>
    </template>
    
    <script>
      import Details from 'views/details.vue';
      import Info from 'views/info.vue';
    
      export default {
        components: {
          Info,
          Details,
        },
        props: ['agent'],
        data: function () {
          return {
            tab_title: 'tab-account-details'
          };
        },
        mounted: function () {
          debugger
        }
      };
    </script>

Answer №1

The reason for this behavior is likely due to Vuetify rendering tabs lazily, which means it doesn't display the content of a tab until it's activated.

To solve this issue, you can utilize the eager prop on the v-tab-item component to force the rendering of hidden tabs. You can find more information in the official documentation

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Ways to inform a subelement that a task is complete?

I have a child component that displays a list of orders passed from the parent. I want to include a "Reload" button inside the child component that, when clicked, triggers a function in the parent component to reload the orders. Upon clicking the reload b ...

I keep getting redirected to a blank page by JS

I've created a JavaScript script that smoothly fades in the page when a user enters it and fades out when they click a link to another page. The script is working as intended, but I'm facing an issue with anchor links on the page. Whenever I clic ...

What is the best practice for using templates in a constructor versus connectedCallback?

Should I apply template in the constructor or connectedCallback of a custom element? In my experience, when I apply it in connectedCallback, sometimes attributeChangedCallback is called before and I can't query for elements. export class TestElement ...

The relentless Livewire Event Listener in JavaScript keeps on running without pausing

I need to create a solution where JavaScript listens for an event emitted by Livewire and performs a specific action. Currently, the JavaScript code is able to listen to the Livewire event, but it keeps executing continuously instead of just once per event ...

Sending form data via Ajax for a specific field ID

When sending data to an ajax script, I usually create a form tag and assign it an id like this: <form id="myForm"> Then, in the ajax script, I include the following code: data: $('#myForm').serialize(), This sends all the form data. How ...

Inject $scope into ng-click to access its properties and methods efficiently

While I know this question has been asked before, my situation is a bit unique. <div ng-repeat="hello in hello track by $index"> <div ng-click="data($index)"> {{data}} </div> </div> $scope.data = function($index) { $scope.sweet ...

Export data from a JSON object to a CSV file within the Osmosis function

I am currently utilizing Osmosis, a node.js tool, to extract data in the form of an array of JSON objects. The behavior of Osmosis functions indicates that the array is confined within the function's scope. Consequently, I must also write the file in ...

Use ajax to load the script

Encountering a puzzling issue with a script loading function on my IIS local web server. function loadJs(scriptName) { var name = scriptName.toString(); var myUrl = 'http://192.168.1.149/7.0.9.5/m/js/'; myUrl += name; debugger; ...

What is the best way to single out a specific item from a list to display in a component upon clicking in Vue.js?

To view the data of a specific item in the child component "comandasInd", I just need to click on the icon. <template> <v-data-table :items="comandas"> <template v-slot:items="props"> <td>{{ props.item.nombre }}</td& ...

"Creating a Hyperlink that Navigates to Specific Content Within a

I have a situation where I am trying to link to sections on the page contained within collapsed fieldsets. My goal is that when a user clicks on this link, the page should scroll down and automatically expand the fieldset to display the content inside. E ...

What is the best way to display a nested JSON object structure?

{ "Title": "Jurassic Park", "Year": "1993", "Rated": "PG-13", "Released": "11 Jun 1993", "Runtime": "127 min", "Genre": "Action, Adventure, Sci-Fi", "Director": "Steven Spielberg", "Writer": "Michael Crichton, David Koepp", "Actors": "Sam ...

Setting a default value in the <v-select> component: A handy guide

After setting up a select component like this: <v-select px-4 class='select' v-model="form.accountType" :items="accountTypes" :label="$t('form.accountType')" :rules="[rules.required, rules.validAccountType]" ...

Best practices for incorporating and leveraging node packages with Laravel Mix

As I embark on my Laravel (v 8.x) Mix project, I am encountering challenges when it comes to incorporating JavaScript from node modules. To kick things off, here is a snippet from my webpack.mix.js: mix.js('node_modules/mxgraph/javascript/mxClient.mi ...

What is the reasoning behind declaring certain variables on the same line as others, while most are declared individually on separate lines?

I've taken on the challenge of learning JS by myself and decided to build a Blackjack game. While following a helpful walkthrough online, I encountered some confusion. On the website, they start by declaring Global variables: var deck; var burnCard; ...

Traversing through an array and populating a dropdown menu in Angular

Alright, here's the scoop on my dataset: people = [ { name: "Bob", age: "27", occupation: "Painter" }, { name: "Barry", age: "35", occupation: "Shop Assistant" }, { name: "Marvin", a ...

Is there any assistance available for incorporating Slimbox and loading images through JavaScript?

I have exhaustively searched online for a solution to my problem, but without any luck. So now I am reaching out to the experts who know exactly what they're doing. Currently, I'm in the process of loading images from Facebook using a handy jQue ...

What could be causing my Chrome extension to function on Mac but not on a PC?

I created a basic Chrome extension that includes a background page with the following code: <script type="text/javascript> chrome.tabs.onDetached.addListener(function(tabId, info){ var id = tabId; chrome.tabs.get(id, function(tab) { ...

The Angular error TS2531 occurs when attempting to call scrollIntoView on an object that may be null

In my current Angular project, I am attempting to implement a scroll view using ViewChild by id. This is the method I have written: ngOnInit() { setTimeout(() => { if (this.router.url.includes('contact')) { ...

Check the document's location if the page contains a class with a specific value

I am encountering an issue while using PHPMailer. I am trying to redirect the page after submitting a form and display a success popup window. After successfully submitting the form, a message is displayed in a popup window (JavaScript adds a class ' ...

Is there a way to combine multiple incoming WebRTC audio streams into one cohesive stream on a server?

I am currently working on developing an audio-conferencing application for the web that utilizes a WebSocket server to facilitate connections between users and enables streaming of audio. However, I am looking to enhance the system by transforming the serv ...