|
@@ -1,8 +1,24 @@
|
|
|
import axios from 'axios'
|
|
|
+import qs from 'qs'
|
|
|
|
|
|
console.log('[debug]当前环境:', process.env)
|
|
|
const service = axios.create({
|
|
|
baseURL: process.env.VUE_APP_BASE_API
|
|
|
})
|
|
|
|
|
|
+service.interceptors.request.use(config => {
|
|
|
+ // 在请求发送之前做一些事
|
|
|
+ if (config.method === 'post' || config.method === 'POST') {
|
|
|
+ if (typeof config.data !== 'string') {
|
|
|
+ config.data = qs.stringify(config.data)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 获取插入token
|
|
|
+ return config
|
|
|
+}, function (error) {
|
|
|
+ // 当出现请求错误是做一些事
|
|
|
+ console.log('--请求超时--', error)
|
|
|
+ return Promise.reject(error)
|
|
|
+})
|
|
|
+
|
|
|
export default service
|