Watch
- watch 监听 props 属性时,不能使用解构赋值
代码语言:javascript
复制// 解构
setup({ notifie }){
const localNotifie = ref({})
const [ set, { add, remove } ] = useSet(localNotifie.value.target)
// notifie 变化时, 无法触发监听
watch( () => notifie, () => {
console.log('watch')
localNotifie.value = cloneDeep(notifie)
})
return {
....
}
}
// 非结构
setup(props){
const localNotifie = ref({})
const [ set, { add, remove } ] = useSet(localNotifie.value.target)
// notifie 变化时, 触发监听
watch( () => props.notifie, () => {
console.log('watch')
localNotifie.value = cloneDeep(props.notifie)
})
return {
....
}
}