vue实现v-for和v-if一起使用的方法

我们一般知道,v-if和v-for因为优先级的问题,所以不能在一起使用,但是有些时候又有这种场景的需要并且也不想改变页面布局。
所以我认为的解决办法是。在使用v-for的的组件外,再包裹一层template标签。再在上面使用v-if,因为template只是包装元素,他并不会在页面中进行任何的渲染。所以也能达到v-if和v-for共同使用。
如:

  <template v-if="false">
                <el-option v-for="item in projectStatus" :value="item.label">
                </el-option>
              </template>

猜你喜欢

转载自blog.csdn.net/weixin_45807026/article/details/126574449