zyb-axios
v1.0.22
Published
axios
Downloads
6
Readme
zyb-axios
安装
npm i zyb-axios -S
// api.js 文件
import zybAxios from 'zyb-axios'
const api = {
get: {
'list': 'http://www.XXXX.com/list'
},
post: {
'setInfo': 'http://www.XXX.com/setInfo'
},
file: {
'uploadpic': 'http://www.XX.com/uploadpic'
}
}
export default zybAxios(api)
// 业务文件
import Http from './api.js'
// get请求
const params = {pageNo: 1, type: 'all'}
Http.list(params).then((data) => {
console.log(data)
})
// post请求
const data = {use: 'kakaxi', pwd: 'kabuda'}
Http.setInfo(data).then(data => {
console.log(data)
})
// file请求
let fd = new FormData()
fd.append('pic', Img)
Http.uploadpic(fd).then(data => {
console.log(data)
})
此外,每种请求还都支持第二个参数args,例如:
const data = {use: 'kakaxi', pwd: 'kabuda'}
Http.setInfo(data, {
timeout: 1000,
withCredentials: false,
.... //参考axios的请求配置
})
注:file请求headers默认 {'content-type': 'multipart/form-data'}