From 07b7474af115114ed57477290f40bd193942f88f Mon Sep 17 00:00:00 2001 From: aixianling Date: Mon, 17 Jun 2024 18:20:13 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B8=85=E7=90=86=E4=B8=80=E4=B8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.vue | 90 +++++--------------------------------- src/components/menu.vue | 26 +++++++++++ src/router/index.js | 36 +++++++-------- src/views/AppSpanTable.vue | 16 +++++++ src/views/HomeView.vue | 6 --- 5 files changed, 69 insertions(+), 105 deletions(-) create mode 100644 src/components/menu.vue create mode 100644 src/views/AppSpanTable.vue delete mode 100644 src/views/HomeView.vue diff --git a/src/App.vue b/src/App.vue index 1f84c74..d6e3aca 100644 --- a/src/App.vue +++ b/src/App.vue @@ -1,86 +1,18 @@ - - - + diff --git a/src/components/menu.vue b/src/components/menu.vue new file mode 100644 index 0000000..166f89f --- /dev/null +++ b/src/components/menu.vue @@ -0,0 +1,26 @@ + + + + diff --git a/src/router/index.js b/src/router/index.js index cf9820b..04343a4 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -1,27 +1,23 @@ import Vue from 'vue' import VueRouter from 'vue-router' -import HomeView from '../views/HomeView.vue' Vue.use(VueRouter) - +const ctx = require.context('../views', true, /\.(\/.+)\/App[A-Z][^\/]+\.vue$/, 'lazy') const router = new VueRouter({ - mode: 'history', - base: import.meta.env.BASE_URL, - routes: [ - { - path: '/', - name: 'home', - component: HomeView - }, - { - path: '/about', - name: 'about', - // route level code-splitting - // this generates a separate chunk (About.[hash].js) for this route - // which is lazy-loaded when the route is visited. - component: () => import('../views/AboutView.vue') - } - ] + mode: 'history', routes: [{ + path: '/', name: 'home', + }] +}) +const routes = [] +await Promise.all(ctx.keys().map(ctx)).then(file => { + if (file.default) { + const {name, label = name, path} = file.default + routes.push({name, path, label}) + router.addRoute({ + path, name, component: file.default + }) + } +}).then(() => { + localStorage.setItem('routes', JSON.stringify(routes)) }) - export default router diff --git a/src/views/AppSpanTable.vue b/src/views/AppSpanTable.vue new file mode 100644 index 0000000..6cde05c --- /dev/null +++ b/src/views/AppSpanTable.vue @@ -0,0 +1,16 @@ + + + + + diff --git a/src/views/HomeView.vue b/src/views/HomeView.vue deleted file mode 100644 index 57c3090..0000000 --- a/src/views/HomeView.vue +++ /dev/null @@ -1,6 +0,0 @@ - - -