vue 使用watch同时监听多个属性

watch监听调用了两个参数,两个参数的出现都调用了一个函数,分开检测就会调用两次

第一种方法

data () {
  return {
     city: '',
     area: '',
     currentPage: ''
  }
},
 
watch: {
   city: function (val) {
 
      // 写要执行的代码片段
 
   },
   area: function (newVal,oldVal) {
 
      // 写要执行的代码片段
 
   }, 
}

第二种


data () {
  return {
     city: '',
     area: '',
     currentPage: ''
  }
},
 
computed: {
    listenChange () {
        const { city, area, currentPage } = this
        return { city, area, currentPage }
    },
},
 
watch: {
   listenChange (val) {
 
      // 写要执行的代码片段
 
   },
    
}