我正在使用Vuex
,Getter Foo function
在数组中返回两个值:
return ["Try Again"]
或return ["Data result", data]
,在计算中,我正在检查array length
并根据结果返回
computed:{
Foo: function(){
const getFoo = this.$store.getters.Foo;
if(getFoo.length === 1) {
this.existFoo = false
return getFoo[0]
}
this.existFoo = true
return getFoo
}
}
但是我遇到这个错误,即使阅读其他帖子也无法解决
34:9错误“ Foo”计算属性vue /没有副作用的
意外副作用37:7错误“ Foo”计算属性vue /没有副作用的意外副作用-特性
您可以使用观察程序来监视商店值并设置本地变量。
computed: {
getFooFromStore() {
return this.$store.getters.Foo
}
}
watch: {
getFooFromStore: function() {
this.existFoo = this.getFooFromStore[0] ? false : true;
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句