x-axios

axios请求封装

Usage no npm install needed!

<script type="module">
  import xAxios from 'https://cdn.skypack.dev/x-axios';
</script>

README

xAxios

axios请求封装

安装

npm install x-axios --save

使用

// main.js
import http from 'x-axios/dist/http.min.js'
Vue.prototype.$http = http
// demo.vue
this.$http.get('/api', {a:1,b:2}).then({data} => {
  // do something
})
this.$http.get('/api?a=1&b=2').then({data} => {
  // do something
})
this.$http.options('/api', {a:1,b:2}).then({data} => {
  // do something
})
this.$http.options('/api?a=1&b=2').then({data} => {
  // do something
})
this.$http.head('/api', {a:1,b:2}).then({data} => {
  // do something
})
this.$http.head('/api?a=1&b=2').then({data} => {
  // do something
})
this.$http.delete('/api', {a:1,b:2}).then({data} => {
  // do something
})
this.$http.delete('/api?a=1&b=2').then({data} => {
  // do something
})
this.$http.post('/api', {a: 1,b: 2}).then({data} => {
  // do something
})
this.$http.put('/api', {a: 1,b: 2}).then({data} => {
  // do something
})
this.$http.patch('/api', {a: 1,b: 2}).then({data} => {
  // do something
})
this.$http.postJson('/api', {a: 1,b: 2}).then({data} => {
  // do something
})
this.$http.putJson('/api', {a: 1,b: 2}).then({data} => {
  // do something
})
this.$http.patchJson('/api', {a: 1,b: 2}).then({data} => {
  // do something
})

API

方法 | 说明 | 参数说明 | -- | -- | -- | | get(url[, params]) | get请求 |

url:请求地址

params:请求参数,可在params传参或使用请求地址query传参

| | options(url[, params]) | options请求 |

url:请求地址

params:请求参数,可在params传参或使用请求地址query传参

| | head(url[, params]) | head请求 |

url:请求地址

params:请求参数,可在params传参或使用请求地址query传参

| | delete(url[, params]) | delete请求 |

url:请求地址

params:请求参数,可在params传参或使用请求地址query传参

| | post(url, data[, config]) | post请求 |

url:请求地址,

data:请求参数,

config:配置信息,参考axios官方文档

| | put(url, data[, config]) | put请求 |

url:请求地址,

data:请求参数,

config:配置信息,参考axios官方文档

| | patch(url, data[, config]) | patch请求 |

url:请求地址,

data:请求参数,

config:配置信息,参考axios官方文档

| | postJson(url, data[, config]) | postJson请求 |

url:请求地址,

data:请求参数,

config:配置信息,参考axios官方文档

| | putJson(url, data[, config]) | putJson请求 |

url:请求地址,

data:请求参数,

config:配置信息,参考axios官方文档

| | patchJson(url, data[, config]) | patchJson请求 |

url:请求地址,

data:请求参数,

config:配置信息,参考axios官方文档

| | upload(url, data[, config]) | 上传文件(实质为post请求) |

url:请求地址,

data:请求参数,

config:配置信息,参考axios官方文档

|