VueJS2:具有多个表达式的v-if不起作用
我试图在HTML元素中使用v-if指令隐藏div元素,如下所示:VueJS2:具有多个表达式的v-if不起作用,vuejs2,Vuejs2,我试图在HTML元素中使用v-if指令隐藏div元素,如下所示: <template v-if="(selectedProducts != 'Static Graphic' || selectedProducts != 'Other Support')"> <div><strong>Content 2 Here</strong></div> </template> 此处为内容2 但是,这不起作用 写这个逻辑/表达式
<template v-if="(selectedProducts != 'Static Graphic' || selectedProducts != 'Other Support')">
<div><strong>Content 2 Here</strong></div>
</template>
此处为内容2
但是,这不起作用
写这个逻辑/表达式的正确方法是什么
谢谢,VueJS有很棒的文档,所以您应该先看看这里 在这里,您可以跳过模板标记并将v-if移动到div中,如下所示:
<div v-if="selectedProducts != 'Static Graphic' || selectedProducts != 'Other Support'">
Now you see me
</div>
现在你看到我了
请看这里:
针对您的具体情况更新:
<template v-if="selectedProducts.indexOf('Static Graphic') > 0 || selectedProducts.indexOf('Other Support') > 0">
<div><strong>Content 2 Here</strong></div>
</template>
此处为内容2
您可以将表达式放在v-if中。
问题在于您的表达式:selectedProducts是一个数组,您无法测试selectedProducts!='静态图形“
试试这个:
v-if="(selectedProducts.indexOf('Static Graphic') < 0 && selectedProducts.indexOf('Other Support') < 0)">
v-if=“(selectedProducts.indexOf('Static Graphic')<0&&selectedProducts.indexOf('Other Support')<0)”>
JSFIDLE:因此,根据VueJS文档,VueJS2中的指令中似乎不允许使用多个表达式。我读对了吗?我应该把这个逻辑移到computed属性中?