VUE-element-admin之配置多级路由菜单

61 篇文章 2 订阅
49 篇文章 9 订阅

步骤:
routers.js中添加如下代码:
在这里插入图片描述

{
    path: '/usermanagement', 
    alwaysShow: true, //是否显示父级:如果为false则只显示最内层菜单(默认false)
    component: Layout,
    hidden: false, //是否显示
    redirect: 'noredirect',
    name: '用户管理',
    meta: { title: '用户管理', icon: 'Steve-Jobs', affix: false, noCache: true },
    //affix:固定标签(不可删除)
    children: [
      {
        path: '/usermanagement/client',
        component: (resolve) => require(['@/views/usermanagement/client'], resolve),
        name: '客户管理',
        meta: { title: '客户管理', icon: 'people' }
      }
    ]
  }

效果图:
在这里插入图片描述
注意:本地配置路由只针对公用菜单,如果牵扯到权限就要动态配置菜单存入数据库。

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
Vue-element-admin 是基于 Vue.js 和 Element UI 实现的后台管理系统框架。它采用了 Vue Router 实现路由跳转和页面切换。在 Vue-element-admin ,实现多级路由缓存可以通过以下步骤: 1. 在路由配置文件,设置需要缓存的路由组件的 meta 属性添加 keepAlive: true。 ``` const routes = [ { path: '/', component: Layout, redirect: '/dashboard', children: [ { path: 'dashboard', component: () => import('@/views/dashboard/index'), name: 'Dashboard', meta: { title: 'Dashboard', icon: 'dashboard', keepAlive: true } } ] } ] ``` 2. 在 App.vue 文件,添加 keep-alive 组件,并设置 include 属性为需要缓存的路由组件的名称。 ``` <template> <div id="app"> <keep-alive :include="cachedViews"> <router-view /> </keep-alive> </div> </template> <script> export default { name: 'App', computed: { cachedViews() { return this.$store.state.tagsView.cachedViews } } } </script> ``` 3. 在 store 文件夹创建 tagsView.js 文件,设置需要缓存的路由组件的名称和缓存状态。 ``` const state = { cachedViews: [] } const mutations = { ADD_CACHED_VIEW: (state, view) => { if (state.cachedViews.includes(view.name)) return if (!view.meta.keepAlive) return state.cachedViews.push(view.name) }, DEL_CACHED_VIEW: (state, view) => { const index = state.cachedViews.indexOf(view.name) if (index > -1) { state.cachedViews.splice(index, 1) } } } const actions = { addCachedView({ commit }, view) { commit('ADD_CACHED_VIEW', view) }, delCachedView({ commit }, view) { commit('DEL_CACHED_VIEW', view) } } export default { namespaced: true, state, mutations, actions } ``` 这样就可以实现多级路由缓存了。需要注意的是,路由组件的名称必须是唯一的,否则可能会出现缓存错误。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

赫兹/Herzz

如果我的博文帮助到您请打赏支持

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值