|
@@ -1,6 +1,20 @@
|
|
|
import axios from 'axios'
|
|
|
|
|
|
const TIME_OUT_MS = 60 * 1000 // 默认请求超时时间
|
|
|
+axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded'
|
|
|
+
|
|
|
+// 请求拦截器
|
|
|
+axios.interceptors.request.use(function (config) {
|
|
|
+ return config
|
|
|
+}, function (error) {
|
|
|
+ return Promise.reject(error)
|
|
|
+})
|
|
|
+// 响应拦截器
|
|
|
+axios.interceptors.response.use(function (response) {
|
|
|
+ return response
|
|
|
+}, function (error) {
|
|
|
+ return Promise.reject(error)
|
|
|
+})
|
|
|
|
|
|
/*
|
|
|
* @param response 返回数据列表
|
|
@@ -49,15 +63,7 @@ function handleParams (data) {
|
|
|
export default {
|
|
|
post (url, data) {
|
|
|
return new Promise((resolve, reject) => {
|
|
|
- axios({
|
|
|
- method: 'post',
|
|
|
- url: handleUrl(url),
|
|
|
- data: handleParams(data),
|
|
|
- timeout: TIME_OUT_MS,
|
|
|
- headers: {
|
|
|
- 'Content-Type': 'application/json; charset=UTF-8'
|
|
|
- }
|
|
|
- }).then(
|
|
|
+ axios.post(url, data).then(
|
|
|
(result) => {
|
|
|
resolve(result)
|
|
|
}
|
|
@@ -68,9 +74,9 @@ export default {
|
|
|
)
|
|
|
})
|
|
|
},
|
|
|
- get (url, params) {
|
|
|
+ get (url) {
|
|
|
return new Promise((resolve, reject) => {
|
|
|
- axios.get(handleUrl(url), {params: params})
|
|
|
+ axios.get(url )
|
|
|
.then(response => {
|
|
|
resolve(response.data)
|
|
|
}).catch(error => {
|