【发布时间】:2020-10-06 21:26:52
【问题描述】:
如果逻辑一次为真,我希望始终显示 compopent。
我尝试添加和设置新的 var ,但得到“canShowAlways”计算属性中的意外副作用。
我如何在 vue 中做到这一点?
<mycomp v-if="canShowAlways" />
data: function(){
return {
a: 0,
b: 4,
c: 1
d: 2,
isAlwaysShow: false
}
}
computed: {
canShowAlways() {
if(this.isAlwaysShow){
return true;
}
var isLast = this.a && this.b || this.c && this.d;
if(isLast){
this.isAlwaysShow = true;
return true;
}
return false;
},
【问题讨论】:
-
这看起来有点奇怪,你的计划是什么,你想要达到什么目标
-
你不应该在计算函数中赋值。为
canShowAlways使用观察者。
标签: vue.js vuejs2 vue-component