watch三种写法

watch: {
    // 方式一:
    'cityName.name': {
        handler(newName, oldName) {
            // ...
        },
        deep: true,
        immediate: true //立即执行
    }
    //方式二:
    cityName(newName, oldName){
        // ...
    }
    //方式三:
    cityName:{
        handler(newName, oldName) {
              // ...
        },
    }
}
方式四:$watch
created(){
  const unwatch = this.$watch("cityName",function(){
   // ...
   },{ 
    deep: true,
    immediate: true 
  })
// unwatch() //一旦变化后就取消监听 }

 

posted @ 2022-02-16 14:28  如意酱  阅读(384)  评论(0)    收藏  举报