当前位置:网站首页>2021-05-20computed and watch applications and differences
2021-05-20computed and watch applications and differences
2022-06-24 09:08:00 【Secret Shura】
VUE And computed and watch Application and difference Catalog :
** watch and computed**
conputed effect :
Calculate the result and return , Triggered only when the calculated value changes
( namely : The results of the calculated properties are cached , Recalculate only if the dependent reactive property changes , Has dependent properties .
( If you are in the name Method to print the time new Data() Multiple prints are the same , because new Data() Not dependent data )
new Vue({
el: '#id',
template: `<div> <span>Name: {
{name}}<span> </div>`,
data: {
firstName: 'Leo',
lastName: 'Alan'
},
computed: {
name () {
return `${
this.firstName} + ${
this.lastName}`
}
}
})
watch effect :
Listen for a value , When the value being monitored changes , Perform the corresponding operation , For example, the following single listening value , And then change data Or do other operations
( And computed Is the difference between the ,watch It is more suitable for monitoring the change of a certain value and doing corresponding operations , For example, request background interface , and computed It is applicable to calculating the existing value and returning the result )
( If you are in the name Print under method new Data() Printing many times is different , because watch A muscle , Update every time )
new Vue({
el: '#id',
template: `<div> // ... </div>`,
data: {
firstName: 'Leo',
lastName: 'Alan',
obj1: {
a: 0
}
},
watch: {
// monitor firstName, When firstName This function is executed when changes occur
firstName () {
// Perform the required actions ...
// notes : Initialization does not execute , Only if the monitored value (firstName) Only when changes occur
},
// monitor lastName
lastName: {
handler (newName, oldName) {
// Perform the required actions ...
},
immediate: true // true: During initialization, the corresponding operation of the listening will be executed first
},
obj1: {
handler () {
// Perform the required actions ...
},
deep: true // The default value of this property is false.
// When the monitored value is an object , Only deep by true when , The value of the corresponding attribute (obj1.a) The listening event can only be triggered when a change occurs , But this is very performance consuming
},
// Listen for specific properties of the object , deep You don't need to set it to true 了
'obj1.a': {
handler () {
// Perform the required actions ...
}
}
}
})
Be careful : Not in computed and watch The modification in is dependent ( Or be monitored ) Value , This may lead to an infinite loop
边栏推荐
- 关于 GIN 的路由树
- Data middle office: overview of data governance
- Code written by mysql, data addition, deletion, query and modification, etc
- 4274. suffix expression
- [MySQL from introduction to mastery] [advanced part] (I) character set modification and underlying principle
- What is graph neural network? Figure what is the use of neural networks?
- Redis implements a globally unique ID
- linux(centos7.9)安装部署mysql-cluster 7.6
- 4275. Dijkstra序列
- Opencv daily function structure analysis and shape descriptor (7) finding polygon (contour) / rotating rectangle intersection
猜你喜欢

cookie加密 4 rpc方法确定cookie加密

Leetcode -- wrong set

Webrtc series - network transmission 5: select the optimal connection switching

uniapp 开发多端项目如何配置环境变量以及区分环境打包

Huawei Router: GRE Technology

用VNC Viewer的方式远程连接无需显示屏的树莓派

"I can't understand Sudoku, so I choose to play Sudoku."

Kaformer personal notes

Telnet port login method with user name for liunx server

EasyExcel单sheet页与多sheet页写出
随机推荐
Remote connection of raspberry pie without display by VNC viewer
【输入法】迄今为止,居然有这么多汉字输入法!
Huawei Router: GRE Technology
uniapp 开发多端项目如何配置环境变量以及区分环境打包
[pytoch basic tutorial 31] youtubednn model analysis
Huawei Router: IPSec Technology
MySQL data (Linux Environment) scheduled backup
1844. replace all numbers with characters
Wan Weiwei, a researcher from Osaka University, Japan, introduced the rapid integration method and application of robot based on WRS system
1528. 重新排列字符串
MySQL | view notes on Master Kong MySQL from introduction to advanced
目标检测系列——Fast R-CNN
"Unusual proxy initial value setting is not supported", causes and Solutions
数组相向指针系列
Groovy通过withCredentials获取Jenkins凭据
4275. Dijkstra序列
【LeetCode】387. 字符串中的第一个唯一字符
嵌入式 | 硬件转软件的几条建议
Floating error waiting for changelog lock
【Redis实现秒杀业务①】秒杀流程概述|基本业务实现