优化架构,新增路由

This commit is contained in:
robin
2022-07-09 02:53:59 +08:00
parent 72b69615b6
commit 626da19438
19 changed files with 588 additions and 95 deletions
+18
View File
@@ -0,0 +1,18 @@
import axios from 'axios'
import request from './request.js'
import requestError from './requestError.js'
import response from './response.js'
import responseError from './responseError.js'
export default (Vue) => {
axios.defaults.baseURL = process.env.VUE_APP_BASE_URL;
axios.defaults.headers.common['Authorization'] = "";
axios.defaults.headers.post['Content-Type'] = 'application/json';
axios.defaults.timeout = 60 * 1000;
// 添加请求拦截器
axios.interceptors.request.use(request, requestError);
// 添加响应拦截器
axios.interceptors.response.use(response, responseError);
Vue.prototype.$api = axios
}
+5
View File
@@ -0,0 +1,5 @@
// 添加请求拦截器
export default (config) => {
// 在发送请求之前做些什么
return config;
}
+5
View File
@@ -0,0 +1,5 @@
// 添加请求错误拦截器
export default (error) => {
// 对请求错误做些什么
return Promise.reject(error);
}
+5
View File
@@ -0,0 +1,5 @@
// 添加响应拦截器
export default (response) => {
// 对响应数据做点什么
return response;
}
+4
View File
@@ -0,0 +1,4 @@
export default (error) => {
// 对响应错误做点什么
return Promise.reject(error);
}
+18 -14
View File
@@ -1,28 +1,32 @@
import Vuex from 'vuex'
const state = {
count: 1
count : 1,
navHead: false,//导航栏是否隐藏
}
const mutations = {
SET_ADD_COUNT : (state) => {
state.count++
// SET_ADD_COUNT : (state) => {
// state.count++
// },
// SET_SUBTRACT_COUNT: (state) => {
// state.count--
// },
//设置navHead
navHead(state, data) {
state.navHead = data
},
SET_SUBTRACT_COUNT: (state) => {
state.count--
}
}
const actions = {
// 加
add({commit}) {
commit('SET_ADD_COUNT')
},
// 减
subtract({commit}) {
commit('SET_SUBTRACT_COUNT')
}
// add({commit}) {
// commit('SET_ADD_COUNT')
// },
// //
// subtract({commit}) {
// commit('SET_SUBTRACT_COUNT')
// }
}
const store = new Vuex.Store({