简易版的axios,可以让你在uniapp中无缝切换成axios。支持axios的功能如下:
Using npm:
$ npm/cnpm install han-uni-axios -S
import uniAxios from 'han-uni-axios'
uniAxios.request({
url:'',
method:'',//不传默认是get
data:{}
})
import uniAxios from 'han-uni-axios'
uniAxios.get({
url:'',
data:{}
})
import uniAxios from 'han-uni-axios'
let http=uniAxios.create({
baseURL
})
http({
url:'',
method:'',
data:{}
})
import uniAxios from 'han-uni-axios'
let http=uniAxios.create({
baseURL
})
//请求拦截
http.interceptors.request.use(config => {
return config
}, error => {
return error
})
// 响应拦截
http.interceptors.response.use(res => {
return res
}, error => {
return error
})
- transformRequestData
转换请求的数据
- transformResponseData
转换请求的数据
- header
修改请求头
- catchErr
返回数据的状态码验证器
以上是自带的四个默认配置项
import uniAxios from 'han-uni-axios'
uniAxios.defaults.header=xx //修改默认配置
uniAxios.defaults.baseURL='' //新值默认配置
import uniAxios from 'han-uni-axios'
let http=uniAxios.create({
header=xx, //修改默认配置
baseURL:'xx'//新值默认配置
})