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/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 }) } 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 new file mode 100644 index 0000000..965aab9 --- /dev/null +++ b/src/config/router.config.js @@ -0,0 +1,41 @@ +/** + * 基础路由 + * @type { *[] } + */ +export const constantRouterMap = [ + { + path: '/', + name: 'index', + component: () => import('@/layouts/AppLayout'), + redirect: '/home', + meta: { + title: '首页', + keepAlive: false + }, + children: [ + { + path: '/', + component: () => import('@/layouts/TabBarLayout'), + redirect: '/home', + 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/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 @@ + + + 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 @@ + + + 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