(method, url, params)
| 17 | |
| 18 | export default class Server { |
| 19 | axios(method, url, params){ |
| 20 | return new Promise((resolve, reject) => { |
| 21 | if(typeof params !== 'object') params = {}; |
| 22 | let _option = params; |
| 23 | _option = { |
| 24 | method, |
| 25 | url, |
| 26 | baseURL: envconfig.baseURL, |
| 27 | timeout: 30000, |
| 28 | params: null, |
| 29 | data: null, |
| 30 | headers: null, |
| 31 | withCredentials: true, //是否携带cookies发起请求 |
| 32 | validateStatus:(status)=>{ |
| 33 | return status >= 200 && status < 300; |
| 34 | }, |
| 35 | ...params, |
| 36 | } |
| 37 | axios.request(_option).then(res => { |
| 38 | resolve(typeof res.data === 'object' ? res.data : JSON.parse(res.data)) |
| 39 | },error => { |
| 40 | if(error.response){ |
| 41 | reject(error.response.data) |
| 42 | }else{ |
| 43 | reject(error) |
| 44 | } |
| 45 | }) |
| 46 | }) |
| 47 | } |
| 48 | } |
no test coverage detected