我的div
Vue有多个不同的if条件,有办法在一个<div>
中添加多个v-if
,
类似的东西
<div v-if="any" v-if="another-any">
</div>
我看到了这一点,但作为一个和条件工作,而不是另一个条件
<div v-if="any && another-any">
</div>
我还看到了OR条件
<div v-if="any || another-any">
</div>
但是在一个div中有两个或多个不同的条件?
如果您的条件太长,无法将其放入v-if
中,只需创建一个计算属性:
computed: {
any() {
return this.isSomething || this.isSomethingElse // || ...
}
}
然后只在模板中使用:<div v-if="any">
是。它们只是在div:中以不同的方式运行
one && other // runs if both return truthy value
one || other // runs if any of them returns truthy value
注意:another-any
是无效变量。变量名称不能包含dash
。