|
@@ -0,0 +1,34 @@
|
|
|
+import axios from 'axios'
|
|
|
+import Qs from 'qs'
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+export default function createHttp (host) {
|
|
|
+ let ax = axios.create({
|
|
|
+ baseURL: host,
|
|
|
+ headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
|
|
+ transformRequest: [function (data) {
|
|
|
+ data = Qs.stringify(data)
|
|
|
+ return data
|
|
|
+ }],
|
|
|
+ transformResponse: [],
|
|
|
+ withCredentials: true
|
|
|
+ })
|
|
|
+
|
|
|
+
|
|
|
+ // 拦截器处理错误
|
|
|
+ ax.interceptors.response.use(
|
|
|
+ async response => {
|
|
|
+ if( response.data.rs) {
|
|
|
+ return Promise.resolve(response)
|
|
|
+ } else {
|
|
|
+ return Promise.reject(response)
|
|
|
+ }
|
|
|
+ },
|
|
|
+ error => {
|
|
|
+ return Promise.reject(error)
|
|
|
+ }
|
|
|
+ )
|
|
|
+
|
|
|
+ return ax
|
|
|
+}
|