Alf*_*ang 20
使用vm创建中的watch部分:
var vm = new Vue({
el: 'body',
data: {
items: []
},
computed: {
item_length: function () {
return this.battle_logs.length;
}
},
watch: {
items: {
handler: function () {
console.log('caught!');
},
deep: true
}
}
});
Run Code Online (Sandbox Code Playgroud)
或者观察计算长度属性:
vm.$watch('item_length', function(newVal, oldVal) {
console.log('caught!');
});
Run Code Online (Sandbox Code Playgroud)
小智 5
在 vue3 设置中查看 items.length
import { watch } from "vue";
watch(
() => items.length,
(newValue,oldValue) => { console.log(newValue,oldValue)}
)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8069 次 |
| 最近记录: |