Vue template syntax, vue Template

Source: Internet
Author: User

Vue template syntax, vue Template

Vue. js uses HTML-based template syntax, allowing developers to explicitly bind DOM to the data of the underlying Vue instance. All Vue. js templates are legal HTML, so they can be parsed by compliant browsers and HTML Parser.

At the underlying implementation level, Vue compiles the Template into a virtual DOM rendering function. In combination with the response system, when the application status changes, Vue can intelligently calculate the minimum cost of re-rendering components and apply them to DOM operations.

1. Insert the plain text "Mustache" Syntax

1 <! DOCTYPE html> 2 

Mustache cannot be used in HTML attributes. Use the v-bind command.

<Div v-bind: id = "dynamicId"> </div>

This attribute also applies to boolean values. If the condition is false, this attribute is removed.

<Button v-bind: disabled = "someDynamicCondition"> Button </button>

2. Use the v-html command to insert html. Data Binding will be ignored.

1 <! DOCTYPE html> 2 

3. for all data bindings, Vue. js provides full support for JavaScript expressions. Each binding can only be a single expression.

1 <! DOCTYPE html> 2 

Print result:

 

4. Some commands can be followed by a parameter, which is indicated by a colon.

<A v-bind: href = "url"> </a> // update html attributes.

<A v-on: click = "doSomething"> // listens for events.

5. Filter

The filter can only be bound to andv-bindExpression (supported from 2.1.0), because the filter is designed for text conversion. The filter function always accepts the value of the expression as the first parameter.

1 <! DOCTYPE html> 2 

Print result:

 

6. Command abbreviations

<Div> <! -- Complete Syntax --> <a v-bind: href = "url"> </a> <! -- Abbreviation --> <a: href = "url"> </a> <! -- Complete Syntax --> <a v-on: click = "doSomething"> </a> <! -- Abbreviation --> <a @ click = "doSomething"> </a> </div>

 

Related Article

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.