Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How does vuejs get elements

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report