一、问题描述
错误描述:翻译过来大概的意思就是缺少一个
key
,来指定相应的属性
warning in ./src/view/Index.vue
(Emitted value instead of an instance of Error) <el-menu-item v-for="item2 in item.children">: component lists rendered with v-for should have explicit k
eys. See https://vuejs.org/guide/list.html#key for more info.
@ ./src/view/Index.vue 11:0-361
@ ./src/router/index.js
@ ./src/main.js
@ multi (webpack)-dev-server/client?http://localhost:8080 webpack/hot/dev-server ./src/main.js
warning in ./src/view/Index.vue
(Emitted value instead of an instance of Error) <el-submenu v-for="item in $router.options.routes">: component lists rendered with v-for should have expl
icit keys. See https://vuejs.org/guide/list.html#key for more info.
@ ./src/view/Index.vue 11:0-361
@ ./src/router/index.js
@ ./src/main.js
@ multi (webpack)-dev-server/client?http://localhost:8080 webpack/hot/dev-server ./src/main.js
warning in ./src/view/Index.vue
(Emitted value instead of an instance of Error) <el-menu-item v-for="item2 in item.children">: component lists rendered with v-for should have explicit k
eys. See https://vuejs.org/guide/list.html#key for more info.
@ ./src/view/Index.vue 11:0-361
@ ./src/router/index.js
@ ./src/main.js
@ multi (webpack)-dev-server/client?http://localhost:8080 webpack/hot/dev-server ./src/main.js
warning in ./src/view/Index.vue
(Emitted value instead of an instance of Error) <el-menu-item v-for="item2 in item.children">: component lists rendered with v-for should have explicit k
eys. See https://vuejs.org/guide/list.html#key for more info.
@ ./src/view/Index.vue 11:0-361
@ ./src/router/index.js
@ ./src/main.js
@ multi (webpack)-dev-server/client?http://localhost:8080 webpack/hot/dev-server ./src/main.js
warning in ./src/view/Index.vue
(Emitted value instead of an instance of Error) <el-submenu v-for="item in $router.options.routes">: component lists rendered with v-for should have expl
icit keys. See https://vuejs.org/guide/list.html#key for more info.
@ ./src/view/Index.vue 11:0-361
@ ./src/router/index.js
@ ./src/main.js
@ multi (webpack)-dev-server/client?http://localhost:8080 webpack/hot/dev-server ./src/main.js
出现警告的代码:
<el-submenu v-for="(item,index) in $router.options.routes" :key="index" :index="index+''">
<template slot="title"><i class="el-icon-message"></i>{{item.name}}</template>
<el-menu-item v-for="(item2,index2) in item.children" :index="item2.path"
:class="$route.path==item2.path?'is-active':''">{{item2.name}}</el-menu-item>
</el-submenu>
二、解决方案
增加语句 :key = “index”,具体位置可参照下面的代码
<el-submenu v-for="(item,index) in $router.options.routes" :key="index" :index="index+''">
<template slot="title"><i class="el-icon-message"></i>{{item.name}}</template>
<el-menu-item v-for="(item2,index2) in item.children" :key="index2" :index="item2.path"
:class="$route.path==item2.path?'is-active':''">{{item2.name}}</el-menu-item>
</el-submenu>
处理之后,再运行项目,警告就没有了。。。
版权声明:本文为gao_jun1原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。