import ajax from 'tiny-axios-wrap'
ajax(config, options)
.then(res => {
})
.catch(err => {
})
config = {
method: 'post',
url: '',
data: {}
}
config = {
method: 'get',
url: '',
params: {}
}
config.timeout = 10000;
config = {
headers: {
'Content-Type': 'application/json'
},
transformRequest: [function (data) {
return JSON.stringify(data);
}]
}
options = {
loading: {
open() {},
close() {}
},
toast: {
open() {},
success() {},
error() {},
warn() {}
},
outputCodes: [],
resCodeIntercept: [
{ code: '', handler() {} }
],
utils: {
auth: {
code: 'code',
num: 0,
message: 'error',
defaultReqErrorBefore: 'rq',
defaultResErrorBefore: 'rs',
defaultReqErrorCode: '000',
defaultResErrorCode: '000',
},
alert: {
timeoutError: '连接超时,请重试',
notFoundData: '没有数据',
otherError: '网络错误'
}
}
}
import axios from 'tiny-axios-wrap'
import Loading from 'tiny-loading'
import Tost from 'tiny-tost'
let ajax = (config) => {
let options = {
loading: Loading,
toast: Tost,
resCodeIntercept: {
code: 202,
handler() {
console.log(202)
}
},
utils: {
auth: {
code: 'code',
num: 0,
message: 'msg'
}
}
}
return new Promise((resolve, reject) => {
axios(config, options)
.then(res => {
res.data.code === 0 && resolve(res.data)
})
.catch(err => reject(err))
})
}
ajax.prototype.then = res => {}
ajax.prototype.catch = err => {}
export default ajax
ajax({
method: 'post',
url: 'http://xxxxxx',
data: {}
})
.then(res => {
console.warn(res);
})
.catch(err => {
console.error(err);
})