vue composition-api tips

2020-04-22  本文已影响0人  copyLeft

Watch


// 解构
 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 {
            ....
        }
    }

上一篇 下一篇

猜你喜欢

热点阅读