Vue3.0 watch监听事件
const state = reactive({count:1})
watch(() => state.count,(newCount,oldCount) =>{
console.log(newCount,'新数据源')
console.log(oldCount,'老数据源')
})
const num = ref(0)
watch(num,(newNum,oldNew) =>{
console.log(newNum,'新数据源')
console.log(oldNew,'老数据源')
})
const state = reactive({count:1})
const num = ref(0)
watch([()=> state.count,num],([newCount,newNum],[oldCount,newOld])=>{
console.log('new:',newCount,newNum);
console.log('old:',oldCount,oldNum);
})
const state = reactive({
person: {
name: '张三',
fav: ['帅哥','美女','音乐']
},
});
watch(() => state.person,(newPerson,oldPerson) =>{
console.log("新值:", newType, "老值:", oldType);
},{
deep:true //立即监听
})