前言
如题,转载
代码
- 监听属性
watch:{ a(newVal,oldVal){ if(newVal != oldVal){ this.sum = newVal+this.b; } console.log("a发生了改变",newVal,oldVal) }
- 监听表单
watch: { 'formData.selectStatus': { handler: function (newVal, oldVal) { if (newVal === '1' || newVal === 1) { this.showHighQuality = true } else { this.showHighQuality = false } }, // 立即生效属性 immediate: true, // 对象内部的属性监听,深度监听 deep: true } }