同一标签上,不能同时使用v-for和v-if,怎么办?

解决方案

将 v-for 写在 template上,key和 v-if 写在循环遍历的元素上

(template上不能使用key, 但 v-for 必须要指定key,所以循环遍历的元素上,需要加上key )

<ul>
    <template v-for="(item,index) in ['国庆节', '春节', '元旦']">
        <li v-if="item !== '春节'" :key="index">{{item}}</li>
    </template>
</ul>

 

Logo

前往低代码交流专区

更多推荐