李明洋*_*李明洋 6 javascript watch vue.js
假设我有两个数据属性:
data() {
return {
a: false,
b: false,
}
}
Run Code Online (Sandbox Code Playgroud)
当a并b成为true在同一时间,我想办理相关任务.
如何在Vue中使用watch方法来实现此目的?
Ber*_*ert 15
观察计算值.
computed:{
combined(){
return this.a && this.b
}
}
watch:{
combined(value){
if (value)
//do something
}
}
Run Code Online (Sandbox Code Playgroud)
上面使用$ watch有一个简短的手.
Run Code Online (Sandbox Code Playgroud)vm.$watch( function () { return this.a + this.b }, function (newVal, oldVal) { // do something } )
| 归档时间: |
|
| 查看次数: |
2169 次 |
| 最近记录: |