前言
在看框架的时候,发现了这样的代码. 查看官方文档好像并没有讲到这个.
1 | watch: { |
watch 监听数组或者对象
handler:监听数组或对象的属性时用到的方法deep:深度监听,为了发现对象内部值的变化,可以在选项参数中指定 deep:true 。注意监听数组的变动不需要这么做。immediate: 在选项参数中指定 immediate: true 将立即以表达式的当前值触发回调tips: 只要bet中的属性发生变化(可被监测到的),便会执行handler函数;如果想监测具体的属性变化,如pokerHistory变化时,才执行handler函数,则可以利用计算属性computed做中间层。
普通的watch
1
2
3
4
5
6
7
8
9
10data() {
return {
frontPoints: 0
}
},
watch: {
frontPoints(newValue, oldValue) {
console.log(newValue)
}
}数组的watch
1 | data() { |