Properly using __vue__

I have written a “tab component” that shows some tabs. Clicking on a tab displays the associated panel with information.

Now I want to e.g. add tabs dynamically (info is pushed by the server) which means that I have to find the instance of the tab component in order to manipulate its data. Trying to do this, I came up with document.querySelector("#instanceId").__vue__. Using __vue__ doesn’t feel right as it is supposed to be a “hidden attribute”. However, registering the instances in some global registry doesn’t feel better and is more difficult to do.

What is the recommended way to find a vue instance of a component by id?

(There is a related issue with no real answer here.)

Hi. Is there different components on different tabs or just on type of component which just renders different data?

It’s one component that renders the tabs. Different instances are used in different contexts. However, the tabs are just an example. I have other components which have instances that I need to find as well.

1 Like

The $children attribute of a component can be used to get its children

Sorry, but how is this supposed to help in finding a particular component instance?

Sorry. I misunderstood you. My thought was you wanted the child components of the tab. But instead of the manipulation of the components could you manipulate the data and components are redrawn then the data changes?

Well, that’s what I want to do. I want to manipulate the data of the component instance. But in order to do this, I need to access the component instance, i.e. I need what is commonly referred to as “vm” when you do “vm = new Vue({el: '#app', ...})”.

Using a component, a new Vue instance is created “automatically” and saved in the __vue__ attribute of the root element of the generated DOM tree. If the template sets the id in the root element using a value from props, I can access the root of the generated DOM with document.querySelector("#instanceId") and then the “vm” with ...__vue__ as initially described.

Now we come back to the initial question: Using __vue__ doesn’t feel right…

Hello i need some help which is not related to this.I can see you are online

It is better to make a new post. Than posting in an unrelated subject.