computed监听vux值变化请求methods 中的方法

创建vuex监听器

  computed: {
    pipeGalleryCode() {
      return this.$store.state.settings.pipeGalleryCode
    }
  },

因为 pipeGalleryCode() 中无法调用方法我们可以在页面中创建watch来监听pipeGalleryCode值的变化

  watch:{
    pipeGalleryCode(curval,oldval){
       this.getStatistics()
    }
  },

在watch中就可以调用 methods方法了

  computed: {
    pipeGalleryCode() {
      return this.$store.state.settings.pipeGalleryCode
    }
  },
  watch:{
    pipeGalleryCode(curval,oldval){
       this.getStatistics()
    }
  },
  methods:{
     getStatistics(){
       console.log('我被调用')
     }
  }

你可能感兴趣的:(vue,技术)