Vue3-admin-element framework study notes----5 (final article--dynamic routing)

Regarding the menu bar on the left, you can add or delete directly, or store the router locally, but this is not a long-term and convenient solution after all.

Idea: Write out all the routers, but judge its permissions before generating the array on the left menu, and perform specified rendering

step:

准备:src>config>setting.js>authentication=='all'(改变为后端控制)
src>roouter   写出所有的文件路径和名称
改变接口
加代理
改变本地端口(8090)

permission.js         src>config>permission.js
routes.js                src>src>store>modules>routes
handleRoutes.js     src>utils>handleRoutes.js



1:permission.js
48: accessRoutes = await store.dispatch('routes/setAllRoutes',本地存储参数);
2:routes.js
38:let accessRoutes = convertRouter(本地存储参数);
3:handleRoutes.js
20:delete route.redirect;




47:当后台为主的时候执行该判断
获取到存储到本地的一个数据
调用上面的数组accessRoutes(复制上面的代码改变括号里面的数据)作用:vuex的一个调用方法和获取到指定数据    
'routes/setAllRoutes', a.roles     routes/setAllRoutes:roters(src>store>modules>routes)里面的setAllRoutes函数
convertRouter(a.roles)方法里面的数据改成你自己的本地数据    convertRouter是src>utils里面的函数 目的是调用选择注册路由
删除数组里面的redirect,因为他指向是他本身

Guess you like

Origin blog.csdn.net/m0_72196169/article/details/130152198