自动引入module跟router
//modeles 引入
const modules = {}
const files = require.context('./modules//对应的文件夹名', true, /\.js$/)
files.keys().forEach(path => {
const module = files(path).default || {}
modules[path.slice(2, -3)] = {
namespaced: true,
...module
}
})
...
module 放入对应的store中
...js
const _routes = []
const files = require.context('./routes', true, /\.js$/)
files.keys().forEach(path => {
const module = files(path).default
if (module) {
_routes.push(module)
}
})
//以下是route
import Layout/每个子路由中要引入的主页面 from '@/layout'/路径
const _routes = []
const files = require.context('./routers//对应的文件夹名', true, /\.js$/)
files.keys().forEach(path => {
const module = files(path).default
if (module) {
_routes.push({
component: Layout,//每个子路由中加入要渲染的主页面 针对于后台管理
...module
})
}
})
export const menuRoutes = _routes //导出用于渲染动态菜单
...menuRoutes 放入对应的routes 中