From 44277e69758f09c245340fa7761f342c12dc59c3 Mon Sep 17 00:00:00 2001 From: xiaodi Date: Sun, 31 May 2020 21:03:29 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E5=88=86=E7=A6=BB=E8=B7=AF=E7=94=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/config/router.config.js | 24 +++++++++++++++++ src/router/index.js | 51 +++++++++++++++++-------------------- 2 files changed, 47 insertions(+), 28 deletions(-) create mode 100644 src/config/router.config.js diff --git a/src/config/router.config.js b/src/config/router.config.js new file mode 100644 index 0000000..add8534 --- /dev/null +++ b/src/config/router.config.js @@ -0,0 +1,24 @@ +/** + * 基础路由 + * @type { *[] } + */ +export const constantRouterMap = [ + { + path: '/', + name: 'index', + component: () => import('@/views/home/index'), // 路由懒加载 + meta: { + title: '首页', // 页面标题 + keepAlive: false // keep-alive 标识 + } + }, + { + path: '/about', + name: 'about', + component: () => import('@/views/home/about'), + meta: { + title: '关于我', + keepAlive: false + } + } +] diff --git a/src/router/index.js b/src/router/index.js index aa5a9f7..7e9538c 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -1,34 +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) -export const router = [ - { - path: '/', - name: 'index', - component: () => import('@/views/home/index'), // 路由懒加载 - meta: { - title: '首页', // 页面标题 - keepAlive: false // keep-alive 标识 - } - }, - { - path: '/about', - name: 'about', - component: () => import('@/views/home/about'), - meta: { - title: '关于我', - keepAlive: false - } - } -] -const createRouter = () => - new Router({ - // mode: 'history', // 如果你是 history模式 需要配置vue.config.js publicPath - // base: '/app/', - scrollBehavior: () => ({ y: 0 }), - routes: router - }) +const createRouter = () => new Router({ + mode: 'history', + base: process.env.BASE_URL, + scrollBehavior: () => ({ y: 0 }), + routes: constantRouterMap +}) -export default createRouter() +const router = createRouter() + +// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465 +export function resetRouter () { + const newRouter = createRouter() + router.matcher = newRouter.matcher // reset router +} + +export default router From a38a270fb278320d530a5bb2245d1f53122b1f1b Mon Sep 17 00:00:00 2001 From: xiaodi Date: Sun, 31 May 2020 21:17:06 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E5=88=86=E7=A6=BB=20api=20=E5=8F=8A=20?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/index.js | 7 +++++++ src/api/user.js | 20 +++++++++++--------- 2 files changed, 18 insertions(+), 9 deletions(-) create mode 100644 src/api/index.js diff --git a/src/api/index.js b/src/api/index.js new file mode 100644 index 0000000..6147745 --- /dev/null +++ b/src/api/index.js @@ -0,0 +1,7 @@ +const api = { + Login: '/user/login', + UserInfo: '/user/userinfo', + UserName: '/user/name' +} + +export default api diff --git a/src/api/user.js b/src/api/user.js index 13e6050..9fbb466 100644 --- a/src/api/user.js +++ b/src/api/user.js @@ -1,22 +1,23 @@ -import qs from 'qs' +import api from './index' + // axios import request from '@/utils/request' -// user api // 登录 -export function login(params) { +export function login(data) { return request({ - url: '/user/login', + url: api.Login, method: 'post', - data: qs.stringify(params) + data }) } + // 用户信息 post 方法 -export function getUserInfo(params) { +export function getUserInfo(data) { return request({ - url: '/user/userinfo', + url: api.UserInfo, method: 'post', - data: qs.stringify(params), + data, hideloading: true }) } @@ -24,8 +25,9 @@ export function getUserInfo(params) { // 用户名称 get 方法 export function getUserName(params) { return request({ - url: '/user/name?' + qs.stringify(params), + url: api.UserName, method: 'get', + params, hideloading: true }) } From 8d89e205271625339fb44f5747608bcab3fcc72e Mon Sep 17 00:00:00 2001 From: xiaodi Date: Sun, 31 May 2020 22:17:06 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.vue | 16 +++--------- src/components/TabBar.vue | 37 ++++++++++++++++----------- src/config/router.config.js | 31 ++++++++++++++--------- src/layouts/TabBarLayout.vue | 48 ++++++++++++++++++++++++++++++++++++ 4 files changed, 94 insertions(+), 38 deletions(-) create mode 100644 src/layouts/TabBarLayout.vue diff --git a/src/App.vue b/src/App.vue index 20397b6..0178e00 100644 --- a/src/App.vue +++ b/src/App.vue @@ -1,21 +1,11 @@ diff --git a/src/components/TabBar.vue b/src/components/TabBar.vue index b04388c..631e926 100644 --- a/src/components/TabBar.vue +++ b/src/components/TabBar.vue @@ -1,28 +1,37 @@ diff --git a/src/config/router.config.js b/src/config/router.config.js index add8534..1d926b7 100644 --- a/src/config/router.config.js +++ b/src/config/router.config.js @@ -6,19 +6,28 @@ export const constantRouterMap = [ { path: '/', name: 'index', - component: () => import('@/views/home/index'), // 路由懒加载 + component: () => import('@/layouts/TabBarLayout'), // 路由懒加载 + redirect: '/home', meta: { title: '首页', // 页面标题 keepAlive: false // keep-alive 标识 - } - }, - { - path: '/about', - name: 'about', - component: () => import('@/views/home/about'), - meta: { - title: '关于我', - keepAlive: false - } + }, + children: [ + { + path: '/home', + name: 'Home', + component: () => import('@/views/home/index'), + meta: { title: '首页', keepAlive: false } + }, + { + path: '/about', + name: 'About', + component: () => import('@/views/home/about'), + meta: { + title: '关于我', + keepAlive: false + } + } + ] } ] diff --git a/src/layouts/TabBarLayout.vue b/src/layouts/TabBarLayout.vue new file mode 100644 index 0000000..26f82a9 --- /dev/null +++ b/src/layouts/TabBarLayout.vue @@ -0,0 +1,48 @@ + + + From fa6a5ced1f62d1a8ef1a494af837553b36a42be0 Mon Sep 17 00:00:00 2001 From: xiaodi Date: Sun, 31 May 2020 22:50:14 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/config/router.config.js | 36 ++++++++++++++++++++++-------------- src/layouts/AppLayout.vue | 14 ++++++++++++++ 2 files changed, 36 insertions(+), 14 deletions(-) create mode 100644 src/layouts/AppLayout.vue diff --git a/src/config/router.config.js b/src/config/router.config.js index 1d926b7..965aab9 100644 --- a/src/config/router.config.js +++ b/src/config/router.config.js @@ -6,27 +6,35 @@ export const constantRouterMap = [ { path: '/', name: 'index', - component: () => import('@/layouts/TabBarLayout'), // 路由懒加载 + component: () => import('@/layouts/AppLayout'), redirect: '/home', meta: { - title: '首页', // 页面标题 - keepAlive: false // keep-alive 标识 + title: '首页', + keepAlive: false }, children: [ { - path: '/home', - name: 'Home', - component: () => import('@/views/home/index'), - meta: { title: '首页', keepAlive: false } - }, - { - path: '/about', - name: 'About', - component: () => import('@/views/home/about'), + path: '/', + component: () => import('@/layouts/TabBarLayout'), + redirect: '/home', meta: { - title: '关于我', + title: '首页', keepAlive: false - } + }, + children: [ + { + path: '/home', + name: 'Home', + component: () => import('@/views/home/index'), + meta: { title: '首页', keepAlive: false } + }, + { + path: '/about', + name: 'About', + component: () => import('@/views/home/about'), + meta: { title: '关于我', keepAlive: false } + } + ] } ] } diff --git a/src/layouts/AppLayout.vue b/src/layouts/AppLayout.vue new file mode 100644 index 0000000..faaa5b3 --- /dev/null +++ b/src/layouts/AppLayout.vue @@ -0,0 +1,14 @@ + + +