1.登陸
在login文件下的index.vue(接口在store文件下modules/user.js)
(登陸頁面如果接口成功但進不去頁面則需要看一下store/modules/pemission.js的
getUserPowers方法,看這里的返回值是不是正確的
)
2.獲取用戶信息
根據getInfo接口后台返回的信息(接口在store文件下modules/user.js)
3.獲取左側菜單
在router.js中的
asyncRoutes設置動態加載路由,才可以設置
在store/modules/pemission.js中,需要修改的是請求getUserPowers接口,獲取后台返回的數據后,使用循環插入layout,最后在自組件中插入組件路徑
(//layout需要引入模塊才可以用,否則報錯)
4.最主要的是下面這段代碼,將遍歷好的數據塞到已有的路由
if (roles.data.roles.includes('admin')) {
// if (roles.includes('admin')) {
// console.log('6dian', asyncRoutes)
accessedRoutes = asyncRoutes || []
} else {
// console.log('7dian')
accessedRoutes = filterAsyncRoutes(asyncRoutes, roles)
}
5.退出登陸
接口在store文件下modules/user.js
asyncRoutes(動態加載路由)變量中,只能寫在
constantRoutes(靜態加載路由)靜態數據中
constantRoutes(靜態加載路由)靜態數據中
解決辦法:后台返回的數據中添加一個參數‘hidden:true/false’,控制是否顯示在左側
//注意:后台返回的路由參數需要和在本地文件router.js中的參數一致