watch 监听函数

接收3个参数,监听源、回调函数((newVal,oldVal) => {})、options配置项{immediate:true, deep:true}

import { ref, watch } from 'vue'
 
let message = ref({
    nav:{
        bar:{
            name:""
        }
    }
})

let message2 = reactive({
    name:"",
    name2:""
})

// 监听单个变量
watch(message, (newVal, oldVal) => {
    console.log('新的值----', newVal);
    console.log('旧的值----', oldVal);
},{
    immediate:true,
    deep:true
})
// 监听多个源
watch(()=>[message,message2], (newVal, oldVal) => {

}
// 监听单个属性
watch(()=>message2.name, (newVal, oldVal) => {

}
Last Updated:
Contributors: haizhiguang