Axios

来源:互联网 发布:五金行业进销存软件 编辑:程序博客网 时间:2024/05/21 20:10

Axios 是基于promise 的HTTP库(可在浏览器和node.js中)

特征:

1. 浏览器中创建XMLHttpRequests2. node.js创建http请求3. 拦截请求和响应4. 客户端支持防御XSRF5....(详细的自己看文档说明)

使用:

GET 请求

//get 方式的参数    //axios.get('/url',{params:{key1:value1}})    axios.get('/url?data=666')    .then(function(msg){})    .catch(function(err){console.log(err)})

POST请求

    axios.post('/url',{        key1:value1,        key2:value2    })    .then(function(msg){})    .catch(function(err){console.log(err)})

多个请求并发

axios.all([fun1(), fun2()])  .then(axios.spread(function (acct, perms) {    // 两个请求现在都执行完成  }));

创建实例:

var instance = axios.create({})

实例方法

axios.create({})

…待续

Axios 中文说明文档
Axios NPM package

原创粉丝点击