v-for 遍历数组展示列表时,报错
index 不能是数值型,需要转换成字符串。
ps:这里只是个demo,后期不建议使用 index 值。
<el-menu-item
v-for="(item,index) in routerList"
:index="index + 1" //错误写法 问题出在这里
// :index="JSON.stringify(index + 1)" //正确写法 转化一下字符串就不报错了
:key="item.path"
>
<span slot="title">
<router-link to="item.path">{{ item.name }}</router-link>
</span>
</el-menu-item>
// js
data(){
return {
routerList:[
{ name:"Home", path:'/', },
{ name:"About", path:'/about', },
],
}
},