import {requestSuccessFunc, requestFailFunc, responseSuccessFunc, responseFailFunc} from './axios' import {routerBeforeEachFunc} from './router' export default { requestSuccessFunc, requestFailFunc, responseSuccessFunc, responseFailFunc, routerBeforeEachFunc }
src/config/interceptors/router.js
/** * 路由beforeach拦截器 */ import {CONSOLE_ROUTER_ENABLE} from '../index' export function routerBeforeEachFunc (to, from, next) { // 打印路由数据 CONSOLE_ROUTER_ENABLE && console.info(`%c 路由to: fullPath: ${to.fullPath}, query: ${JSON.stringify(to.query, '', 2)}, meta: ${JSON.stringify(to.meta, '', 2)} 路由from: fullPath: ${from.fullPath} `, 'color: green;font-weight: bold;') // 登录状态验证 if (to.meta.requireLogin) { (localStorage.getItem('token')) ? next() : next({path: '/login', query: { redirect: to.fullPath }}) return } // 路由重定向 // if (to.query.route) { // let newQuery = Object.assign({}, to.query) // delete newQuery.route // next({ // path: `${to.query.route.indexOf('https://www.jb51.net/') === 0 ? '' : 'https://www.jb51.net/'}${to.query.route}`, // query: newQuery // }) // return // } // console.log(to, from) // 防止死循环 if (to.fullPath === from.fullPath) return // 404错误 if (!to.name) { next('/404') return } next() }
src/locale目录
国际化配置,这个百度一下就行
src/mixin目录
引入配置文件,定义部分全局变量,名字自己定义
src/mixin/index.js