基于vue-router 2+Element UI的动态生成导航及相关问题
基于vue-router 2+Element UI的动态生成导航及相关问题
·
本文章是自学vue-router 2时随手记录的,有代码缺失或者缺少说明的请谅解,本文章只限参考。
1、动态的生成导航菜单
<el-menu :router="true" :default-active="$route.path" background-color="#545c64" text-color="#fff" active-text-color="#ffd04b">
<template v-for="route in $router.options.routes">
<el-menu-item v-if="!route.children || route.children.length == 1" :index="route.path" :key="route.path">
<i class="el-icon-menu"></i>{{ route.name }}
</el-menu-item>
<el-submenu v-else :index="route.path" :key="route.path">
<template slot="title">
<i class="el-icon-menu"></i>{{ route.name }}</template>
<el-menu-item v-for="child in route.children" :index="route.path + '/' + child.path" :key="route.path + '/' + child.path">{{ child.name }}</el-menu-item>
</el-submenu>
</template>
</el-menu>
2、问题:使用mode: ‘history’时,进行二级目录的刷新会出现404的问题
解决方法是在webpack中的devServer下配置historyApiFallback: true来解决
更多推荐
已为社区贡献3条内容
所有评论(0)