vue-admin-template 动态路由的实现(方式二 推荐)

本文介绍如何在Vue-admin-template中实现动态路由,包括登录接口、退出接口和详情接口的数据交互,以及如何根据角色权限设置动态路由。在`router/index.js`和`store/modules`中进行改造,通过`permission.js`过滤动态路由,并在`user.js`中处理登录、获取用户信息和权限,提供了一个完整的动态路由和权限管理方案。
摘要由CSDN通过智能技术生成

url: Api.TakeOut,

method: ‘get’

})

}

登录接口数据

{‘code’: 200, ‘data’: {‘token’: ‘X-admin’}, ‘message’: “操作成功”}

退出接口数据

{‘code’: 200, ‘data’: ‘success’, ‘message’: “操作成功”}

详情接口数据

{

“code”: 200,

“data”: {

“avatar”: “https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif”,

“name”: “黄晓果”,

“roles”: [

“editor”

]

}

}

  • 改造router/index.js

import Vue from ‘vue’

import Router from ‘vue-router’

Vue.use(Router)

/* Layout */

import Layout from ‘@/layout’

// 基础路由

export const constantRoutes = [

{

path: ‘/login’,

component: () => import(‘@/views/login/index’),

hidden: true

},

{

path: ‘/404’,

component: () => import(‘@/views/404’),

hidden: true

},

{

path: ‘/’,

component: Layout,

redirect: ‘/dashboard’,

children: [{

path: ‘dashboard’,

name: ‘Dashboard’,

component: () => import(‘@/views/dashboard/index’),

meta: { title: ‘首页’, icon: ‘el-icon-menu’ }

}]

},

]

/**

  • 动态路由

*/

export const asyncRoutes = [

{

path: ‘/studentinformation’,

component: Layout,

children: [

{

path: ‘index’,

component: () => import(‘@/views/studentinformation/index’),

meta: { title: ‘学生信息’, icon: ‘el-icon-s-check’ }

}

]

},

{

path: ‘/lecturerinformation’,

component: Layout,

children: [

{

path: ‘index’,

component: () => import(‘@/views/lecturerinformation/index’),

meta: { title: ‘讲师信息’, icon: ‘el-icon-s-custom’, roles: [‘editor’] }

}

]

},

{

path: ‘/coursemanage’,

component: Layout,

meta: { roles: [‘admin’] },

children: [

{

path: ‘index’,

component: () => import(‘@/views/course

  • 20
    点赞
  • 28
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值