Vue3中watch监听写法


侦听ref和reactive

const state = reactive({
	count: 0
})

// 侦听reactive中属性,需要包裹在箭头函数中
watch(() => state.count, (newVal, oldVal) => {
	
})

// watch直接接受ref作为监听对象,并且在回调函数返回解包后的值
const count = ref(0);
watch(count, (newVal, oldVal) => {
	
})

// 监听props上属性的变化
watch(() => props.msg, (newVal, oldVal) => {
	console.log(newVal, oldVal);
})


posted @ 2023-05-17 21:16  Felix_Openmind  阅读(107)  评论(0)    收藏  举报
*{cursor: url(https://files-cdn.cnblogs.com/files/morango/fish-cursor.ico),auto;}