Simple understanding of the instance property VM in Vue. $els _javascript Skills

Source: Internet
Author: User

Vue Instance property vm. What the hell is $els? What do you need to be aware of? Please read this article specifically.

Do not need an expression

parameters: ID (required)

Usage:

Registers an index for DOM elements to facilitate access to this element through the $els of the owning instance.

Attention:

Because HTML is case-insensitive, camelcase names like V-el:someel will be converted to all lowercase. You can use V-el:some-el to set this. $els. Someel.

My understanding:$els Similar to the Document.queryselector ('. class ') feature, you can get the specified DOM element.

Eg:

<div v-el:maincontainer></div>

var _dom = this. $els. Maincontainer

Note: When fetching the DOM element, the hump name is not recognized, as in the example above, the bound value is Maincontainer, but the DOM can only be written maincontainer, otherwise it will not be recognized.

In fact, in the last article I used the Vue instance attribute vm. $els

HTML code:

<input type= "text" class= ' name-input ' placeholder= ' please fill in the project name ' v-on:keyup.enter= ' Saveprojectfun ' V-el:addproject >

JS Code:

When the user presses ENTER, save the added item
 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;
 }

Actually this . $els. Addproject.value is equivalent to:document.queryselector ('. Name-input '). Value

This article has been organized into the "Vue.js front-end component Learning course", welcome to learn to read.

The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.