vue learning (grammar)

v-html command

You can insert the corresponding page code in the page and display the effect.
Insert picture description here

v-bind instruction

The following example judges the value of use, if it is true, the style of class1 is used, otherwise the class is not used. Refer to the following address:
https://www.runoob.com/vue2/vue-template-syntax.html
https://cn.vuejs.org/v2/guide/syntax.html
Insert picture description here
Insert picture description here

Vue.js provides full JavaScript expression support.

Insert picture description here

v-if instruction

Judgment instructions. Here, the v-if instruction will determine whether to insert the p element according to the value of the expression seen (true or false).
Insert picture description here
Insert picture description here

v-model directive

Two-way data binding. The p note calls the value of the lb variable, and the input and lb variables are two-way data-bound, so whatever you enter in the input box, the p note will immediately display what it is. The advantage of this is that the value of the input box and the value of the lb variable are the same no matter what, if you need to submit the form, you can directly transfer the value of the lb variable. This command can also be used in other places, such as input, select, textarea, checkbox, radio and other form control elements.
Insert picture description here

v-on instruction

(Abbreviated as @) button events we can use v-on to monitor events. In this example, v-on (@) is used to monitor the button, and if it is clicked, it triggers the reverseLc method.
Insert picture description here
Insert picture description here

Filters

Vue.js allows you to customize filters, which are used for some common text formatting. The filter function accepts the value of the expression as the first parameter. The following example converts the first letter of the input string to uppercase:
Insert picture description here

v-if v-else-if v-else 指令

It's a simple if-else.
v-if:
Insert picture description here
Insert picture description here

v-else:
Insert picture description here
v-else-if:
Insert picture description here
Insert picture description here
Insert picture description here

v-show command

You can use the v-show command to display elements based on conditions
Insert picture description here
Insert picture description here

v-for instruction

Cycle instructions, cycle a data set,
Insert picture description here
display the attribute value of an object,
Insert picture description here
display key-value pairs,
Insert picture description here
display key-value pairs and add the serial number to
Insert picture description here
directly cycle integers
Insert picture description here

computed (computed attributes) and methods (methods)

We can use methods instead of computed. The effect is the same for both, but computed is based on its dependency cache, and the value will be re-valued only when the related dependency changes. With methods, when re-rendering, the function will always be called and executed again. It can be said that computed performance will be better, but if you don't want caching, you can use the methods attribute.
Insert picture description here

Monitor attribute watch

Insert picture description here
Insert picture description here

Style binding

We can set an object for v-bind:class to dynamically switch class:
Insert picture description here
Insert picture description here
multiple styles to render at the same time.
Insert picture description here
Insert picture description here
Insert picture description here
Use styles to write objects for rendering.
Insert picture description here
Note: A problem was found when writing styles to object rendering. If the active3 and active4 positions are reversed , Active4 is invalid (as follows).
Insert picture description here
In addition, we can also bind the calculated properties of the returned object here. This is a commonly used and powerful pattern:
Insert picture description here
we can pass an array to v-bind:class, an example is as follows:
Insert picture description here
we can also use a ternary expression to switch the class in the list:
Insert picture description here

Event handler, v-on instruction

Insert picture description here
v-on can receive a defined method to call.
Insert picture description here
Insert picture description here
Insert picture description here
In addition to directly binding to a method, you can also use inline JavaScript statements:
Insert picture description here
Insert picture description here
Insert picture description here

Guess you like

Origin blog.csdn.net/MYNAMEL/article/details/114025226