vue composition-api tips
作者:
copyLeft | 来源:发表于
2020-04-22 16:05 被阅读0次
Watch
- watch 监听 props 属性时,不能使用解构赋值
// 解构
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 {
....
}
}
本文标题:vue composition-api tips
本文链接:https://www.haomeiwen.com/subject/adaiihtx.html
网友评论