Analysis of Vue's template syntax, calculated properties, and listeners

不言
Release: 2018-07-17 16:32:10
Original
1366 people have browsed it

The content shared with you in this article is about the analysis of Vue’s template syntax, calculated properties and listeners. Friends in need can refer to it.

TemplateSyntax,ComputationProperties and listeners

Goal:

1,Proficient in usingvue’stemplate syntax

2. Understand theusageandapplication scenariosof computed properties

and listeners

1.Template syntax

first: {{firstName}}
last: {{lastName}}
{{firstName + ' ' + lastName}}

123

Copy after login

2. Computed properties(computed)

Computed properties and methods are different,Computed properties are cached based on their dependencies,,When the relevant variables of the calculated attribute change, the calculation will be recalculated,Otherwise, the previous calculation result will be read directly from the cache.(This can reduce performance consumption)

Computed properties includegetterandsetter,You can define the functions that will be executed when setting and getting the value respectively.

3. Listener(watch)

If we only need to listen to one piece of data,or perform some operations when a piece of data changes(To change multiple data),And these changes may not have dependencies on this data,then you can use the listener.

##Listener,can listen for changes in a data,Then perform the corresponding operations.

4. Usage scenarios

1. Scenarios that watch

is good at processing: a data Affecting multiple data(One change)2.computed
Scenarios that are good at processing: one data is affected by multiple data(Multiple changes,Finally returns one data)

3.method

relative Normally,needs to actively trigger,may also make the code complicated,And if the scenarios like the above,usemethod, there will be greater performance consumption.

Related recommendations:

vue life cycle, vue instance, template syntax

The above is the detailed content of Analysis of Vue's template syntax, calculated properties, and listeners. 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!