vue监听多个变量的方法

vue当中有时需要监听多个变量,方法如下,推荐方法一

一、把多个变量放在一个对象里

data() {
    return {   
      switchParam: {
        a: false,
        b: false,
        c: false
      }
    }
}

watch: {  
    switchParam: {
      deep: true,
      handler(newVal) {
        let dom = document.querySelector('.vis-panels-controler');
        if (newVal.a || newVal.b || newVal.c) {
          dom.style.zIndex = 180;
        } else {
          dom.style.zIndex = 120;
        }
      }
    },
}

 

二、小技巧方法

data() {
    return {
      a: false, // 自主分析
      b: false,
      c: false
    }
  },
  computed: {   
   allPanelShow() {
    this.a;
    this.b;
    this.c;
  return Date.now() } }, watch: { allPanelShow() { let dom = document.querySelector('.vis-panels-controler'); if (this.a || this.b || this.c) { dom.style.zIndex = 180; } else { dom.style.zIndex = 120; } }, }

 

posted on 2017-11-06 15:42  前端开发小柒  阅读(863)  评论(0编辑  收藏  举报

导航