监听

要监听的数据

  //必须写 要不然getter拿不到改变之后的数据

  this.$store.commit("webdeptId", deptId); 
 
vuex
// 储存全局值
    state: {
        deptId: '',
    },
// 计算器属性
    getters: {
        fruitsCount(state) {
            return state.deptId;
        },
    },
// 操作方法
    mutations: {
        //监听的数据
        webdeptId(state, deptId) {
            state.deptId = null;   //vue监听不到数组的改变 所以清空重置一下就好咯
            state.deptId = deptId
        },
    },
 
监听的页面
 computed: {
    count() {
      return this.$store.state.deptId;
    },
  },
触发的函数    //computed中的方法与watch中的方法一致
  watch: {
    count(newCount, oldCount) {
      console.log(newCount);
     }
  },
posted @ 2019-11-27 14:16  白白了个白白  阅读(129)  评论(0编辑  收藏  举报