老师, wtach可以直接监听reactive的对象吗
来源:6-9 watch 和 watchEffect 的使用和差异性(1)

weixin_慕前端9168190
2022-09-10
我尝试写了以下代码,watch的函数pre 和 cur的值打印都一样的。
const app = Vue.createApp({
setup(props, context) {
const {reactive, watch} = Vue
let nameObj = reactive({name:'', engName:''})
watch(nameObj, (curNameObj, preNameObj) => {
console.log(curNameObj,preNameObj) //这里两个打印都一样的
})
return {
nameObj
}
},
template: `
<div >
Name: <input v-model="nameObj.name"/>
EngName :<input v-model="nameObj.engName" />
</div>
`,
})
写回答
1回答
-
Dell
2022-09-12
用了reactiv 对象,完全没有必要用 watch。
00
相似问题