问题
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