侦听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);
})
标签:count,reactive,watch,newVal,oldVal,Vue3,监听
From: https://www.cnblogs.com/openmind-ink/p/17410329.html