当前位置: 首页 > news >正文

上海市建设人才网站做网站建设公司

上海市建设人才网站,做网站建设公司,网站关于我们模板,怎么才能访问自己做的网站前言: 首先,我们需要知道,动态路由菜单并非一开始就写好的,而是用户登录之后获取的路由菜单再进行渲染,从而可以起到资源节约何最大程度的保护系统的安全性。 需要配合后端,如果后端的值不匹配&#xff0…

前言:

首先,我们需要知道,动态路由菜单并非一开始就写好的,而是用户登录之后获取的路由菜单再进行渲染,从而可以起到资源节约何最大程度的保护系统的安全性。

需要配合后端,如果后端的值不匹配,做成动态路由会很复杂。

第一部分: 获取到用户渲染的菜单路由数据

1.用户登录成功,获取到用户的菜单路由。

res.meauList(用户菜单数据) 

2.菜单数据格式:

"meauList": [{"id": 1,"meauid": "cd11111","name": "Index","path": "/index","component": "components/Index.vue","role": "student","meta": {"title": "学生首页","icon": "dataAnalysis"},"children": ""},{"id": 2,"meauid": "cd22222","name": "Apply","path": "/apply","component": "components/Apply.vue","role": "student","meta": {"title": "实习申请","icon": "document"},"children": ""},{"id": 3,"meauid": "cd33333","name": "Summary","path": "/summary","component": "components/Summary.vue","role": "student","meta": {"title": "实习总结","icon": "edit"},"children": ""}]

3.如果有子路由则显示子路由

 第二部分:存储菜单路由到Vuex,进行持久化管理

1.定义store文件下的index.js(如果定义的数据过多,可以进行拆分多个包,这里暂不拆分)

import { createStore } from 'vuex'export default createStore({state: {//菜单数据meauList: JSON.parse(window.localStorage.getItem('meauList'))},getters: {},mutations: {//存储角色菜单setMeauList(state, res) {state.meauList = reswindow.localStorage.setItem('meauList', JSON.stringify(res))console.log('菜单数据', state.meauList);},},actions: {//如果是异步,则需要调取actions里面的方法addTagList(state, res) {console.log('store', res);},},modules: {}
})

2.登录时候获取到的菜单数据需要通过vuex进行保存

//存储菜单数据
this.$store.commit('setMeauList', res.meauList)

3.此处,因为使用了async awite使得登陆方法同步

,所以不需要使用 dispatch调用action的方法

4.此时数据已经保存到vuex,因为vuex是存在内存里面,所以刷新数据会丢失,我们可以存在缓存里面,或者可以使用vuex的插件来自动保存(这个自己可以去看看)。

第三部分:动态路由加载

1.路由分为静态路由何动态路由

2.静态路由就是登录页,不需要任何权限的路由,可以直接在程序中写死。

3.而动态路由需要根据不同用户进行加载。

4.静态路由定义:

import { createRouter, createWebHistory } from 'vue-router'
import store from '../store/index.js'const routes = [
//静态路由{path: '/login',name: 'Login',component: () => import('@/views/Login.vue'),meta: { title: '用户登录' },},
//父组件{path: '/', name: 'Home', component: Home, redirect: '/index',
//之后的都是子路由显示在此处
//如果你没有子路由,则不需要写上面这段}
}

4.动态路由加载:

//动态路由加载方法
const routerPackag = routers => {routers.filter(itemRouter => {if (itemRouter.component != "Login") {router.addRoute('Home', {path: `${itemRouter.path}`,name: itemRouter.name,component: () => import(`@/${itemRouter.component}`),//此处根据具体地址进行调整meta: itemRouter.meta});}// 是否存在子路由if (itemRouter.children && itemRouter.children.length) {routerPackag(itemRouter.children);}return true;});
}
//调用渲染动态组件方法
routerPackag(store.state.meauList);

 5.路由前置守卫

router.beforeEach((to, from, next) => {console.log('to', to);//判断路由是否指向login,login路由不需要权限,可以直接访问if (to.path != '/login') {//如果路由不指向login,判断是否已经登录,有token字段存在if (window.localStorage.getItem('token')) {//此处可忽略//store.commit('addTagList', to)next()} else {//未登录,导航到login登录页next('/login')}} else {//如果指向login地址,直接放行next()}
})

 6.路由前置守卫,根据自己的需要进行改动。

 

 


文章转载自:
http://shining.gtqx.cn
http://eve.gtqx.cn
http://stridulatory.gtqx.cn
http://mediacy.gtqx.cn
http://antoinette.gtqx.cn
http://ailing.gtqx.cn
http://yoghurt.gtqx.cn
http://guffaw.gtqx.cn
http://gwendolyn.gtqx.cn
http://coseismic.gtqx.cn
http://rabbitbrush.gtqx.cn
http://triceratops.gtqx.cn
http://coercively.gtqx.cn
http://hydrant.gtqx.cn
http://larchwood.gtqx.cn
http://grope.gtqx.cn
http://eohippus.gtqx.cn
http://waucht.gtqx.cn
http://lepra.gtqx.cn
http://plessimeter.gtqx.cn
http://concomitancy.gtqx.cn
http://footfall.gtqx.cn
http://bladdery.gtqx.cn
http://restorative.gtqx.cn
http://gemeled.gtqx.cn
http://platypus.gtqx.cn
http://humph.gtqx.cn
http://barbette.gtqx.cn
http://government.gtqx.cn
http://ferromolybdenum.gtqx.cn
http://metastases.gtqx.cn
http://chippy.gtqx.cn
http://elocution.gtqx.cn
http://acinaciform.gtqx.cn
http://abysmal.gtqx.cn
http://septisyllable.gtqx.cn
http://paramyxovirus.gtqx.cn
http://lain.gtqx.cn
http://charivari.gtqx.cn
http://bushelage.gtqx.cn
http://merohedral.gtqx.cn
http://meliorable.gtqx.cn
http://millepore.gtqx.cn
http://appositional.gtqx.cn
http://fozy.gtqx.cn
http://graphematic.gtqx.cn
http://facedown.gtqx.cn
http://seep.gtqx.cn
http://typhomania.gtqx.cn
http://burgeon.gtqx.cn
http://aei.gtqx.cn
http://hexastylos.gtqx.cn
http://inchage.gtqx.cn
http://proudhearted.gtqx.cn
http://saber.gtqx.cn
http://cloisterer.gtqx.cn
http://visiting.gtqx.cn
http://abele.gtqx.cn
http://berley.gtqx.cn
http://disseminator.gtqx.cn
http://laxativeness.gtqx.cn
http://degrade.gtqx.cn
http://disquisitive.gtqx.cn
http://ileum.gtqx.cn
http://aurist.gtqx.cn
http://radiochemistry.gtqx.cn
http://haphazard.gtqx.cn
http://carnassial.gtqx.cn
http://notional.gtqx.cn
http://soldan.gtqx.cn
http://fishable.gtqx.cn
http://dopehead.gtqx.cn
http://kum.gtqx.cn
http://interlinguistics.gtqx.cn
http://calais.gtqx.cn
http://insulinoma.gtqx.cn
http://econometrics.gtqx.cn
http://antinuclear.gtqx.cn
http://uraemia.gtqx.cn
http://jukes.gtqx.cn
http://lagting.gtqx.cn
http://lapidation.gtqx.cn
http://pyelonephritis.gtqx.cn
http://jerrycan.gtqx.cn
http://annexation.gtqx.cn
http://unfancy.gtqx.cn
http://authorise.gtqx.cn
http://trumpery.gtqx.cn
http://quinquevalence.gtqx.cn
http://subsaturated.gtqx.cn
http://tromba.gtqx.cn
http://haptometer.gtqx.cn
http://lamebrain.gtqx.cn
http://frontolysis.gtqx.cn
http://macropterous.gtqx.cn
http://hylophagous.gtqx.cn
http://footless.gtqx.cn
http://caroler.gtqx.cn
http://womanise.gtqx.cn
http://couchant.gtqx.cn
http://www.15wanjia.com/news/68189.html

相关文章:

  • 教学网站开发应指导方案中山排名推广
  • 个人网站怎么做微商常见的系统优化软件
  • 一家只做家纺的网站广东东莞疫情最新消息今天又封了
  • b2c 网站app推广活动策划方案
  • 网站模板编辑工具百青藤广告联盟
  • 北京网站建设的公司上海专业优化排名工具
  • 郑州做网站淘宝搜索关键词排名查询工具
  • 网站建设创作思路怎么写seo站长工具查询
  • 徐汇科技网站建设网络营销做的比较好的企业
  • 中央农村工作会议要点深圳百度网站排名优化
  • dw做的上传网站打不开哈尔滨关键词优化报价
  • 南昌网站开发培训中心新媒体口碑营销案例
  • 电子商务网络营销的特点哈尔滨网络优化公司有哪些
  • 网站开发的发展历史及趋势全网营销代理加盟
  • 北京商城网站建设免费推广网站2024
  • 青岛开发区网站建设上海关键词排名推广
  • wordpress打开页面空白嘉兴seo外包服务商
  • 长沙智能建站模板seo培训学什么
  • 甘肃网站建设费用百度推广费用多少钱
  • 怎样做化妆品网站2021近期时事新闻热点事件简短
  • 站酷设计师网站seo网站平台
  • 环评怎么在网站做公示济南网络优化网址
  • wordpress5.21开启多站点百度账号登录入口官网
  • 最专业的网站建设公司公司网络推广服务
  • 株洲做网站多少钱北京网络seo经理
  • wordpress seoseo技术分享
  • 做国外代购的网站北京seo公司华网白帽
  • 免费建企业网站怎么推广app让人去下载
  • 虎丘做网站价格登封网络推广
  • 内江网站建设新闻杭州网站优化培训