|
|
@@ -16,7 +16,8 @@ const instance = axios.create({
|
|
|
withCredentials: true
|
|
|
})
|
|
|
|
|
|
-Vue.prototype.$http = axios // 并发请求
|
|
|
+// 并发请求
|
|
|
+Vue.prototype.$http = axios
|
|
|
// 在全局请求和响应拦截器中添加请求状态
|
|
|
const loading = null
|
|
|
|
|
|
@@ -38,6 +39,7 @@ instance.interceptors.response.use(
|
|
|
if (loading) {
|
|
|
loading.close()
|
|
|
}
|
|
|
+
|
|
|
const code = response.status
|
|
|
if ((code >= 200 && code < 300) || code === 304) {
|
|
|
return Promise.resolve(response.data)
|
|
|
@@ -45,14 +47,15 @@ instance.interceptors.response.use(
|
|
|
return Promise.reject(response)
|
|
|
}
|
|
|
},
|
|
|
- error => {
|
|
|
+ error => {
|
|
|
if (loading) {
|
|
|
loading.close()
|
|
|
}
|
|
|
+
|
|
|
if (error.response) {
|
|
|
switch (error.response.status) {
|
|
|
case 401:
|
|
|
- // 返回401 清除token信息并跳转到登陆页面
|
|
|
+ // 返回 401 清除token信息并跳转到登陆页面
|
|
|
console.log('401 错误...')
|
|
|
Vue.$cookies.remove('token')
|
|
|
store.commit('USER_LOGOUT')
|
|
|
@@ -86,14 +89,6 @@ instance.interceptors.response.use(
|
|
|
)
|
|
|
|
|
|
// HTTP 请求
|
|
|
-export function get(url, params) {
|
|
|
- return instance({
|
|
|
- method: 'get',
|
|
|
- url,
|
|
|
- params
|
|
|
- })
|
|
|
-}
|
|
|
-
|
|
|
export function post(url, data) {
|
|
|
return instance({
|
|
|
method: 'post',
|
|
|
@@ -117,3 +112,11 @@ export function delete0(url, data) {
|
|
|
data: JSON.stringify(data)
|
|
|
})
|
|
|
}
|
|
|
+
|
|
|
+export function get(url, params) {
|
|
|
+ return instance({
|
|
|
+ method: 'get',
|
|
|
+ url,
|
|
|
+ params
|
|
|
+ })
|
|
|
+}
|