From 4de3a4aca8333b9f65d2bea77c334e554b63e2b6 Mon Sep 17 00:00:00 2001 From: gaoshuaixing Date: Thu, 17 Dec 2020 19:15:14 +0800 Subject: [PATCH] 1 --- frontend/src/config/router.config.js | 26 +++++++++++++ frontend/src/main.js | 2 + frontend/src/router/index.js | 29 ++++++++++++++ frontend/src/views/Contenta.vue | 58 ++++++++++++++++++++++++++++ frontend/src/views/Contentb.vue | 58 ++++++++++++++++++++++++++++ frontend/src/views/Layout.vue | 10 +++-- frontend/vue.config.js | 5 +++ 7 files changed, 184 insertions(+), 4 deletions(-) create mode 100644 frontend/src/config/router.config.js create mode 100644 frontend/src/router/index.js create mode 100644 frontend/src/views/Contenta.vue create mode 100644 frontend/src/views/Contentb.vue create mode 100644 frontend/vue.config.js diff --git a/frontend/src/config/router.config.js b/frontend/src/config/router.config.js new file mode 100644 index 0000000..1eceb24 --- /dev/null +++ b/frontend/src/config/router.config.js @@ -0,0 +1,26 @@ +/** + * 基础路由 + * @type { *[] } + */ +export const constantRouterMap = [ + // { + // path: '/test', + // redirect: '/testa', + // hidden: true, + // children: [ + // { + // path: '/testa', + // name: 'testa', + // component: { template: '
foo
' } + // }, + // { + // path: '/testb', + // name: 'testb', + // component: () => import(/* webpackChunkName: "user" */ '../views/Contentb') + // } + // ] + // }, + { path: '/testa', component: () => import('@/views/Contenta') }, + { path: '/testb', component: () => import('@/views/Contentb') } + + ] \ No newline at end of file diff --git a/frontend/src/main.js b/frontend/src/main.js index fe86c1b..c70fc1d 100644 --- a/frontend/src/main.js +++ b/frontend/src/main.js @@ -2,11 +2,13 @@ import Vue from 'vue'; import antd from 'ant-design-vue'; import 'ant-design-vue/dist/antd.css'; import App from './App'; +import router from './router'; Vue.use(antd); Vue.config.productionTip = false; new Vue({ + router, render: h => h(App), }).$mount('#app'); \ No newline at end of file diff --git a/frontend/src/router/index.js b/frontend/src/router/index.js new file mode 100644 index 0000000..e3658b4 --- /dev/null +++ b/frontend/src/router/index.js @@ -0,0 +1,29 @@ +import Vue from 'vue' +import Router from 'vue-router' +import { constantRouterMap } from '@/config/router.config' + +// hack router push callback +const originalPush = Router.prototype.push +Router.prototype.push = function push (location, onResolve, onReject) { + if (onResolve || onReject) return originalPush.call(this, location, onResolve, onReject) + return originalPush.call(this, location).catch(err => err) +} + +Vue.use(Router) + +// const Foo = { template: '
foo
' } +// const Bar = { template: '
bar
' } +// const constantRouterMap = [ +// { path: '/testa', component: Foo }, +// { path: '/testb', component: Bar } +// ] + +// const constantRouterMap = [ + +// { path: '/testb', component: () => import('@/views/Contentb') } +// ] + +export default new Router({ + mode: 'history', + routes: constantRouterMap +}) diff --git a/frontend/src/views/Contenta.vue b/frontend/src/views/Contenta.vue new file mode 100644 index 0000000..e4e3908 --- /dev/null +++ b/frontend/src/views/Contenta.vue @@ -0,0 +1,58 @@ + + + + + + diff --git a/frontend/src/views/Contentb.vue b/frontend/src/views/Contentb.vue new file mode 100644 index 0000000..4ada15e --- /dev/null +++ b/frontend/src/views/Contentb.vue @@ -0,0 +1,58 @@ + + + + + + diff --git a/frontend/src/views/Layout.vue b/frontend/src/views/Layout.vue index 587d57d..fdc7b42 100644 --- a/frontend/src/views/Layout.vue +++ b/frontend/src/views/Layout.vue @@ -17,13 +17,15 @@ > - {{ menuInfo.title }} + + {{ menuInfo.title }} +
- content +
@@ -52,11 +54,11 @@ export default { 'menu_1' : { 'subMenu_1' : { title: 'home菜单1', - page: '' + page: '/testa' }, 'subMenu_2' : { title: 'home菜单2', - page: '' + page: '/testb' }, }, 'menu_2' : { diff --git a/frontend/vue.config.js b/frontend/vue.config.js new file mode 100644 index 0000000..12d4ddb --- /dev/null +++ b/frontend/vue.config.js @@ -0,0 +1,5 @@ +module.exports = { + //Solution For Issue:You are using the runtime-only build of Vue where the template compiler is not available. Either pre-compile the templates into render functions, or use the compiler-included build. + //zhengkai.blog.csdn.net + runtimeCompiler: true + } \ No newline at end of file