点击菜单跳转到指定路由

This commit is contained in:
xing 2020-06-17 18:04:40 +08:00
parent cc1ff07808
commit 594dbfde93
3 changed files with 34 additions and 18 deletions

View File

@ -13,7 +13,7 @@
<el-menu unique-opened :collapse="isCollapsed" :collapse-transition="false" <el-menu unique-opened :collapse="isCollapsed" :collapse-transition="false"
background-color="#313743" background-color="#313743"
text-color="#fff" router text-color="#fff" router :default-active="activeNav"
active-text-color="#3497FF"> active-text-color="#3497FF">
<el-submenu :index="item.id + ''" v-for="item in menuList" :key="item.id"> <el-submenu :index="item.id + ''" v-for="item in menuList" :key="item.id">
<!-- 一级菜单模板 --> <!-- 一级菜单模板 -->
@ -24,11 +24,15 @@
<span>{{item.authName}}</span> <span>{{item.authName}}</span>
</template> </template>
<!--二级菜单--> <!--二级菜单-->
<el-menu-item :index="'/'+subitem.path" v-for="subitem in item.children " :key="subitem.id + ''"> <el-menu-item :index="'/'+subitem.path" v-for="subitem in item.children " :key="subitem.id + ''"
<!--图标--> @click="saveNavActive('/'+subitem.path)"
<i class="el-icon-menu"></i> >
<!--文本--> <template slot="title">
<span>{{subitem.authName}}</span> <!--图标-->
<i class="el-icon-menu"></i>
<!--文本-->
<span>{{subitem.authName}}</span>
</template>
</el-menu-item> </el-menu-item>
</el-submenu> </el-submenu>
</el-menu> </el-menu>
@ -58,7 +62,8 @@ export default {
145: 'iconfont icon-baobiao' 145: 'iconfont icon-baobiao'
}, },
isCollapsed: false, isCollapsed: false,
width: '200px' width: '200px',
activeNav: sessionStorage.getItem('menuActive')
} }
}, },
methods: { methods: {
@ -69,6 +74,9 @@ export default {
sessionStorage.clear() sessionStorage.clear()
this.$router.push('/login') this.$router.push('/login')
}, },
saveNavActive (nav) {
sessionStorage.setItem('menuActive', nav)
},
async getMenuList () { async getMenuList () {
const { data: res } = await this.$http.get('menus') const { data: res } = await this.$http.get('menus')
if (res.meta.status !== 200) { if (res.meta.status !== 200) {

View File

@ -0,0 +1,14 @@
<template>
<div class="users">
<h1>user lists</h1>
<pre v-text="$attrs"/>
</div>
</template>
<script>
export default {
props: {
}
}
</script>
<style lang="less" scoped></style>

View File

@ -3,26 +3,20 @@ import VueRouter from 'vue-router'
import Login from '../components/Login' import Login from '../components/Login'
import Home from '../components/Home' import Home from '../components/Home'
import welcome from '../components/welcome' import welcome from '../components/welcome'
import users from '../components/users/users'
Vue.use(VueRouter) Vue.use(VueRouter)
const routes = [ const routes = [
{ { path: '/', redirect: '/login' },
path: '/', redirect: '/login' { path: '/login', component: Login },
},
{
path: '/login',
component: Login
},
{ {
path: '/home', path: '/home',
component: Home, component: Home,
redirect: '/welcome', redirect: '/welcome',
children: [ children: [
{ { path: '/welcome', component: welcome },
path: '/welcome', { path: '/users', component: users }
component: welcome
}
] ]
} }
] ]