Home  >  Article  >  Web Front-end  >  Method to obtain dom elements based on vue1 and vue2

Method to obtain dom elements based on vue1 and vue2

亚连
亚连Original
2018-05-29 16:32:461823browse

Below I will share with you a method of obtaining dom elements based on vue1 and vue2. It has a good reference value and I hope it will be helpful to everyone.

vue1.*In version

Add el='dom' to the tag, and then add this.$els.dom in the code In this way, you get the page element

For example:

Hello

Make your good color appear in red: this.$els.my-box.style.color = 'red'

##vue2.*version

Add ref='dom' in the tag, and then add this.$refs.dom in the code to get the page element

For example:

Hello

Make the color of Hello appear red: this.$refs.myBox.style. color = 'red

The above is what I compiled for everyone. I hope it will be helpful to everyone in the future.

Related articles:

Detailed explanation of VUE Extension of ElTableColumn in element-ui

Detailed explanation of Vue custom dynamic component instance

Introduction to time-sharing functions for javascript performance optimization

The above is the detailed content of Method to obtain dom elements based on vue1 and vue2. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn