工欲善其事必先利其器

This commit is contained in:
2024-06-17 21:16:49 +08:00
parent 89baf6b8e4
commit 619530eb18
7 changed files with 79 additions and 129 deletions

View File

@@ -2,22 +2,22 @@ import Vue from 'vue'
import VueRouter from 'vue-router'
Vue.use(VueRouter)
const ctx = import.meta.glob('../views/App*.vue')
const ctx = import.meta.glob('../views/App*.vue', {eager: true})
const router = new VueRouter({
mode: 'history', routes: [{
path: '/', name: 'home',
}]
})
const routes = []
await Promise.all(ctx.keys().map(ctx)).then(file => {
console.log(ctx)
await Promise.all(Object.values(ctx).map(file => {
if (file.default) {
const {name, label = name, path} = file.default
let {name, label = name, path = name} = file.default
routes.push({name, path, label})
router.addRoute({
path, name, component: file.default
})
return router.addRoute("home", {path, name, component: () => file.default})
}
}).then(() => {
})).then(() => {
localStorage.setItem('routes', JSON.stringify(routes))
})
export default router