Add more than one v-if with different conditions for one div without duplicate?

余生颓废 提交于 2020-01-07 08:32:32

问题


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?


回答1:


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">




回答2:


Yes. They run differently just within that div:

one && other // runs if both return truthy value
one || other // runs if any of them returns truthy value

Caution: another-any is invalid variable. Variable name cannot contain dash.



来源:https://stackoverflow.com/questions/53594222/add-more-than-one-v-if-with-different-conditions-for-one-div-without-duplicate

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!