Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DOM element to corresponding vue.js component

How can I find the vue.js component corresponding to a DOM element?

If I have

element = document.getElementById(id); 

Is there a vue method equivalent to the jQuery

$(element) 
like image 710
Ghigo Avatar asked Nov 13 '14 17:11

Ghigo


People also ask

How do I get DOM element in Vue?

If we want to reference a DOM element, we can use the ref attribute in Vue. Vue can store references to DOM elements in a property called $ref . The first thing we have to do, is add a ref attribute to the element we want to reference in our Javascript.

How do I reference an element in Vue?

Refs are Vue. js instance properties that are used to register or indicate a reference to HTML elements or child elements in the template of your application. If a ref attribute is added to an HTML element in your Vue template, you'll then be able to reference that element or even a child element in your Vue instance.

Which type of DOM is used by VUE JS?

You see that Vue virtual DOM is made of Vue components, which are JavaScript objects that extend the Vue instance. Vue uses a virtual DOM because of the sheer difference in speed and efficiency compared to the actual DOM. The virtual DOM is also smaller in size than the actual DOM and so is very efficient.

How do I transfer data from components to Vue?

VueJS props are the simplest way to share data between components. Props are custom attributes that we can give to a component. Then, in our template, we can give those attributes values and — BAM — we're passing data from a parent to a child component!


1 Answers

Just by this (in your method in "methods"):

element = this.$el; 

:)

like image 123
Kamil Kiełczewski Avatar answered Sep 23 '22 09:09

Kamil Kiełczewski