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('我被调用') } }
watch 常用属性示例 可以在页面进入字段变化组件刷新的时候监听回调
watch: { leaveTypeList: { deep: true, immediate: true, handler(val) { this.gettypeList(val); }, }, },