解决深度监听对象,消耗性能的问题

将对象通过JSON.stringify 方法处理,这时候只要监听字符串变化就行了。

  data(){
    return {
      obj:{
        a:{
          b:{
            c:{
              d:['xx']
            }
          }  
        }  
      }
    }
  }
  computed: {
    watchObj() {
      return JSON.stringify(this.obj);
    },
  },
  watch: {
    watchObj(val) {
      console.log(val)
    },
  },

你可能感兴趣的:(解决深度监听对象,消耗性能的问题)