提交 d3e1b1ed authored 作者: 王鹏飞's avatar 王鹏飞

router 优化

上级 3f051998
......@@ -8,13 +8,18 @@
<span @click="logout">退出登录</span>
</div>
</div>
<el-menu class="nav" :unique-opened="true" :router="true" :default-active="activeLink">
<el-menu class="nav" :unique-opened="true" :default-active="activeLink">
<template v-for="item in datalist">
<el-submenu :index="item.title" :key="item.title" v-if="item.children">
<template #title>
<i class="iconfont" :class="item.icon"></i><span>{{ item.title }}</span>
</template>
<el-menu-item :index="item.path" :key="item.title" v-for="item in item.children">
<el-menu-item
:index="item.path"
:key="item.title"
v-for="item in item.children"
@click="handleClick(item.path)"
>
<template #title>
<template v-if="item.href">
<a :href="item.href" target="_blank">{{ item.title }}</a>
......@@ -24,7 +29,7 @@
</el-menu-item>
</el-submenu>
<el-menu-item :index="item.path" :key="item.title" v-else>
<el-menu-item :index="item.path" :key="item.title" @click="handleClick(item.path)" v-else>
<i class="iconfont" :class="item.icon"></i>
<span slot="title">{{ item.title }}</span>
</el-menu-item>
......@@ -64,9 +69,7 @@ export default {
{
title: '实训练习',
icon: 'icon-kaoshihong',
children: [
{ title: '实训案例练习', path: 'https://xtraining.ezijing.com/', href: 'https://xtraining.ezijing.com/' }
]
children: [{ title: '实训案例练习', href: 'https://xtraining.ezijing.com/' }]
},
{
title: '个人中心',
......@@ -121,6 +124,9 @@ export default {
this.$store.dispatch('logout').then(() => {
window.location.href = webConf.others.loginUrl
})
},
handleClick(path) {
path && this.$router.push(path)
}
}
}
......
......@@ -3,7 +3,11 @@ import Router from 'vue-router'
import routes from './routes'
Vue.use(Router)
const originalPush = Router.prototype.push
Router.prototype.push = function push(location, onResolve, onReject) {
if (onResolve || onReject) return originalPush.call(this, location, onResolve, onReject)
return originalPush.call(this, location).catch(err => err)
}
export default new Router({
routes,
mode: 'history', // 还有一个 hash 默认
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论