Vue vue/cli3 与 vue/cli4 v-for 和 v-if 一起使用冲突

server/2024/10/18 10:58:23/

问题描述

异常信息:[vue/no-use-v-if-with-v-for]
The 'this.$router.options.routers' expression 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 
,如下图:

原因分析:
        error The ‘this.$router.options.routes’ expression 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’ vue/no-use-v-if-with-v-for

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

解决方法

将v-for用template标签进行包裹即可,因在该标签无特殊含义,代码如下:

<el-menu router>
           <template v-for="(item,index) in this.$router.options.routers" >
                        <el-submenu index="1" 
                        :key="index"
                        v-if="!item.hidden">
                            <template slot="title">
                                <i class="el-icon-location"></i>
                                <span>{{item.name}}</span>
                            </template>
                                <el-menu-item 
                                :index="children.path" 
                                v-for="(children,index) in item.children" 
                                :key="index">{{children.name}}</el-menu-item>
                        </el-submenu>
          </template>
</el-menu>

上面代码为vue/cli4中写法,貌似vue/cli3中可以直接像下面这样写:

<el-menu router>

                    <el-submenu index="1"

                    v-for="(item,index) in this.$router.options.routers"

                    :key="index"

                    v-if="!item.hidden">

                        <template slot="title">

                            <i class="el-icon-location"></i>

                            <span>{{item.name}}</span>

                        </template>

                            <el-menu-item

                            :index="children.path"

                            v-for="(children,index) in item.children"

                            :key="index">{{children.name}}</el-menu-item>

</el-submenu>


http://www.ppmy.cn/server/105451.html

相关文章

出现 2003 - Can’t connect to MySQL server on ‘xxx‘(10060) 解决方法

目录 1. 问题所示2. 原理分析3. 解决方法1. 问题所示 sql链接远程服务器的时候,出现如下问题: 2003 - Can’t connect to MySQL server on xxx(10060)截图如下所示: 2. 原理分析 错误代码 10060 表示“连接超时”,说明客户端在尝试连接到服务器时,服务器没有响应或者响…

【论文阅读】DaST: Data-free Substitute Training for Adversarial Attacks(2020)

摘要 Machine learning models&#xff08;机器学习模型&#xff09; are vulnerable&#xff08;容易受到&#xff09; to adversarial examples&#xff08;对抗样本&#xff09;. For the black-box setting&#xff08;对于黑盒设置&#xff09;, current substitute atta…

getchar(),putchar(),EOF的详细解释

文章目录 getchar(),putchar(),EOF的意义和作用一、相关函数putchar( )getchar&#xff08;&#xff09; 二、EOF 的值三、总结 getchar(),putchar(),EOF的意义和作用 在 C 语言中&#xff0c;EOF 是 End Of File 的缩写&#xff0c;即文件结束标志。 在读取文件时&#xff0…

chromedriver下载地址大全(包括124.*后)以及替换exe后仍显示版本不匹配的问题

Chrome for Testing availability CNPM Binaries Mirror 若已经更新了系统环境变量里的chromdriver路径下的exe&#xff0c;仍显示版本不匹配&#xff1a; 则在cmd界面输入 chromedriver 会跳出version verison与刚刚下载好的exe不匹配&#xff0c;则再输入&#xff1a; w…

SmartGit-Git版本控制系统的图形化客户端

SmartGit&#xff1a; SmartGit是一款免费的、专业的Git版本控制系统的图形化客户端。它适用于Windows、Mac和Linux等多种操作系统&#xff0c;提供了直观的用户界面和丰富的功能。支持创建、克隆、推送、拉取、合并和管理Git仓库&#xff0c;以及强大的分支管理功能。还提供了…

OpenCV基本使用教程

OpenCV&#xff08;Open Source Computer Vision Library&#xff09;是一个开源的计算机视觉库&#xff0c;用于处理图像和视频的分析和处理。下面是OpenCV的基本使用教程&#xff1a; 安装OpenCV&#xff1a;首先需要下载和安装OpenCV库。可以在OpenCV的官方网站上找到适合你…

flume--数据从kafka到hdfs发生错误

解决&#xff1a; #1.将flume自带的依赖删除 mv /opt/installs/flume1.9/lib/guava-11.0.2.jar /opt/installs/flume1.9/lib/guava-11.0.2.jar.bak #2.将hadoop的依赖发送到flume下 cp /opt/installs/hadoop3.1.4/share/hadoop/common/lib/guava-27.0-jre.jar /opt/installs/f…

jom.exe 是一个并行构建工具,专门为使用 Microsoft Visual C++ 编译器的 Qt 项目加速编译过程

jom.exe 是一个并行构建工具,专门为使用 Microsoft Visual C++ 编译器的 Qt 项目加速编译过程。它是 nmake 的一个替代品,nmake 是微软提供的标准命令行构建工具,但它不支持并行编译。jom 则弥补了这一不足,能够利用多核处理器的优势,极大地提高编译速度。 1. 基本概念 并…