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('
Vue’s built-in instructions
1. v-bindv-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:
v-bind can be abbreviated as ":",
The above example can be abbreviated as
The implementation effect is as follows:
Bind event listener , abbreviated as @.
We also used it yesterday, let’s abbreviate it to see the effect
The effect is as follows:
##3.v- html
v-html, the parameter type is string,
is used to update innerHTML,acceptedstring
will not be compiled Wait for the operation,The code is as followsThe 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 htmlInterpolationText: Use "Mustache" syntax (double curly brackets) {{value}}Function: Replace the attribute value on the instance,When the value changes, the interpolated content will automatically updateNative html: double curly braces output text and will not parse htmlAttributes: use v-bind Binding can respond to changesUse 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
Have you noticed any surprising changesThere can only be one root node
Write the html structure in a pair of script tags, set type="X-template" 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 functionrender functionAttributes of render option objectcreateElement(tag name, {data object}, [child element]);The child elements are text or arraysLet’s use a piece of code to demonstrate
The effect is as followsSummarizeThe 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!