Home > Web Front-end > JS Tutorial > Simple understanding of instance attributes vm.$els in vue

Simple understanding of instance attributes vm.$els in vue

高洛峰
Release: 2016-12-03 09:36:17
Original
1850 people have browsed it

What exactly is the vue instance attribute vm.$els? What should we pay attention to? Please read this article for details.

No expression required

Parameters: id (required)

Usage:

Register an index for the DOM element to facilitate accessing this element through $els of the instance it belongs to.

Note:

Because HTML is not case-sensitive, camelCase names such as v-el:someEl will be converted to all lowercase. This.$els.someEl can be set with v-el:some-el.

My understanding: $els is similar to the function of document.querySelector('.class'), which can get the specified dom element.

Eg:

var _dom = this.$els.maincontainer

Note: When fetching the dom element, the camel case naming is not recognized, as in the example above, The bound value is mainContainer, but you can only write maincontainer when fetching dom, otherwise it will not be recognized.

HTML code:

 <input type="text" class=&#39;name-input&#39; placeholder=&#39;请填写项目名称&#39; v-on:keyup.enter=&#39;saveProjectFun&#39; v-el:addProject>
Copy after login

js code:

//当用户按回车后,保存添加的项目
 saveProjectFun:function(){
 var obj={}
 obj.success=false;
 let name=this.$els.addproject.value;
 obj.projectName=name.replace(/\s+/g,""); 
 this.projectData.push(obj);
 this.addp=true;
 }
Copy after login

In fact, this.$els.addproject.value is equivalent to: document.querySelector('.name-input').value

Related labels:
vue
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template