How does vuejs get elements
This article mainly explains "how to get elements from vuejs". The content in the article is simple and clear, easy to learn and understand. Please follow the editor's train of thought to study and learn "how to get elements from vuejs".
Vuejs method to get the element: 1, open the corresponding code file; 2, bind the element to "ref=" XXX "; 3, through" this.$refs.XXX "or" this.refs ['XXX'] "to get.
This article operating environment: windows7 system, Vue2.0 version, DELL G3 computer.
How does vuejs get elements?
Get dom elements in Vue
Although Vue.js is said to be data-driven, sometimes we have to get dom objects to do some operations.
Different versions of vue have different ways to get dom objects
In Vue.js version 1. 0, it is bound through v-el and then obtained through this.els.XXX.
In version 2.0 of Vue.js. We get it by binding ref= "XXX" to the element and then through this.$refs.XXX or this.refs ['XXX']
Take 2.0 as an example:
Hello World ~ Click export default {methods: {get () {console.log (this.$refs ['hello']); console.log (this.$refs.hello);}
You need to be careful with dom in vue, especially when adding or removing dom, especially mounted () and created (), when the dom object has not yet been generated and should be placed in the callback function of this.nextTick ().
Thank you for your reading, the above is the content of "how to get the elements of vuejs". After the study of this article, I believe you have a deeper understanding of how to obtain the elements of vuejs, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!