vue使用添加依赖
npm -i 需要安装的依赖包(-S=–save 环境依赖,-D 开发依赖)
npm install --registry=https://registry.npm.taobao.org
questions1 路由懒加载
export const loadView = (view) => { // 路由懒加载
return () => import(/* webpackChunkName: "view-[request]" */ `@/views/${view}`)}
报错
import ``,ESLint: Cannot read property 'range' of null... 路由懒加载
解决方案:手动更改package.json
"babel-eslint": "8.0.1",之后重新npm install
const loadView = (view) => { // 路由懒加载
// return () => import(`@/views/${view}`) 替换成下一行
return resolve => require([`@/views/${view}`], resolve)
}
q2动态加载路由权限中的坑
1,在src/permission.js下添加代码动态添加权限,进行添加
getMenus()
.then(res => {
// 定义动态路由
const asyncRouter = filterAsyncRouter(res.menu_list)
// 添加任意匹配不到任意路由界面访问404
asyncRouter.push({ path: '*', redirect: '/404', hidden: true })
store.dispatch('permission/GenRoutes', asyncRouter)
// 存储路由到state.addRouters
router.addRoutes(store.getters.addRouters) // 动态添加可访问路由表
router.options.routes = store.getters.routers
console.log('store.getters.addRouters', store.getters.addRouters)
next({ ...to, replace: true })// hack方法 确保addRoutes已完成
})
2, 更改sidebar下index文件
computed: {