为一个div添加多个不同条件的v-if而不重复? [英] Add more than one v-if with different conditions for one div without duplicate?
本文介绍了为一个div添加多个不同条件的v-if而不重复?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的 div
Vue 有多个不同的 if 条件,有一种方法可以在一个
中添加多个
v-if
,类似的东西
我看到了这个,但它是作为一个和条件工作的,而不是另一个条件
我也看到了 OR 条件
但是在一个 div 中有 2 个或更多不同的条件?
解决方案
如果你的条件太长而无法将它放在 v-if
中,只需创建一个计算属性:
计算:{任何() {返回 this.isSomething ||this.isSomethingElse//||...}}
然后在模板中使用它:<div v-if="any">
I've div
Vue with more than one different if condition, there is way to add more than one v-if
in one <div>
,
Something like that
<div v-if="any" v-if="another-any">
</div>
I saw this but working as a and condition, not another condition
<div v-if="any && another-any">
</div>
And also I saw OR condition
<div v-if="any || another-any">
</div>
But there are 2 or more different conditions in one div?
解决方案
If your condition is too long to put it inside a v-if
, just create a computed property:
computed: {
any() {
return this.isSomething || this.isSomethingElse // || ...
}
}
and then just use it in template: <div v-if="any">
这篇关于为一个div添加多个不同条件的v-if而不重复?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文