Discussion on components and templates in Vue.js

黄舟
Release: 2017-10-28 09:29:28
Original
1363 people have browsed it

Abstract:

Directive is an important feature in Vue.js. It mainly provides a mechanism to map data changes to DOM behavior. What changes in data are mapped to DOM behaviors? Vue.js is driven by data, so we will not directly modify the DOM structure, and there will be no similar $('ul').append('

  • one
  • ') such an operation, when the data changes, the instruction will modify the DOM with a set operation, so that you can only focus on the data changes without having to manage DOM changes and Status,

    Vue’s built-in instructions

    1. v-bind

    v-bind It is mainly used to bind DOM element attributes (attributes).

    That is, the actual value of the element attribute is provided by the data attribute in the vm instance.

    For example:

        Vue的指令  
       

    {{message}}

    Copy after login

    v-bind can be abbreviated as ":",

    The above example can be abbreviated as

    The implementation effect is as follows:

    2. v-on

    Bind event listener , abbreviated as @.

    We also used it yesterday, let’s abbreviate it to see the effect

        Vue的指令  
       

    {{message}}

    Copy after login

    The effect is as follows:

    ##3.v- html

    v-html, the parameter type is string,

    is used to update innerHTML,

    accepted

    string

    will not be compiled Wait for the operation,

    Process it as normal HTML

    The code is as follows

        Vue的指令  
       

    Copy after login

    The effect is as follows

    For more built-in instructions, please check the official website: Vue.js instructions

    template

    html template

    DOM-based templates, templates are all available Parse valid html

    Interpolation

    Text: Use "Mustache" syntax (double curly brackets) {{value}}

    Function: Replace the attribute value on the instance,

    When the value changes, the interpolated content will automatically update

    Native html: double curly braces output text and will not parse html

    Attributes: use v-bind Binding can respond to changes

    Use JavaScript

    Expression: You can write simple expressionsString template

    template string

    -- Attribute of template option object

    ’ s ’ ’ s ’ s ’ s through through ’s ’ using ’s ’ using ’s ’ through through ’s through through ’s' ’ ‐ to ‐‐‐‐‐‐mn to Content hanging from the element will be ignored.

    The code is as follows

        template模板  
       

    Copy after login
    Have you noticed any surprising changes

    There can only be one root node

    Write the html structure in a pair of script tags, set type="X-template"

        template模板  
       

    vue

    Copy after login

    The effect is as follows:

    Writing in script tags is still relatively limited.

    If other files also have this structure,

    this cannot be reused.

    Template render function

    render function

    Attributes of render option object

    createElement(tag name, {data object}, [child element]);

    The child elements are text or arrays

    Let’s use a piece of code to demonstrate

        render函数   
      

    Copy after login
    The effect is as follows

    Summarize

    The above is the detailed content of Discussion on components and templates in Vue.js. For more information, please follow other related articles on the PHP Chinese website!

    Related labels:
    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
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!