v-for和v-if一起使用时的坑

在同一个标签上使用v-for和v-if会提示错误

[vue/no-use-v-if-with-v-for]
The 'menu' variable inside 'v-for' directive should be replaced with a computed property that returns filtered array instead. You should not mix 'v-for' with 'v-if'.eslint-plugin-vue

代码如下:

原因:v-for的优先级会高于v-if,因此v-if会重复运行在每个v-for中。

vue官网

在这里插入图片描述

正确写法:将 v-if 和 v-for 分别放在不同标签中

猜你喜欢

转载自blog.csdn.net/weixin_42217154/article/details/110872456