vue3定义的reactive对象,比如const user = reactive({
firstName: 'zhang',
lastName: '三',
});
为什么里面的属性比如user.firstName,在html模板中正常绑定实现响应式使用,在watch监听中它就不是响应式了,前面必须加()=>才能用,user.firstName到底是不是响应式?
<el-input v-model="user.firstName" />
watch([user.firstName, user.lastName], (val) => {
console.log('=========');
});
这样不会打印执行,改成这样才能打印执行
watch([()=>user.firstName, ()=>user.lastName], (val) => {
console.log('=========');
});