使用vue-cli脚手架搭建的项目,v-for与v-if不能同时使用,会报错
<el-submenu
index="1"
v-for="(item, index) in this.$router.options.routes"
:key="index"
v-if="!item.hidden"
>
<template slot="title"><i class="el-icon-message"></i>{{ item.name }}</template >
</el-submenu>
解决方案之一:使用计算属性
<el-submenu index="1" v-for="(item, index) in aitemList" :key="index">
<template slot="title"><i class="el-icon-message"></i>{{ item.name }}</template >
</el-submenu>
computed: {
aitemList: function () {
return this.$router.options.routes.filter((item) => {
return item.hidden
})
}
}