Axios 是一个基于 promise 的 HTTP 库,可以用在浏览器和 node.js 中。
使用 npm:
$ npm install axios
使用 bower:
$ bower install axios
使用 CDN:
<script src="https://unpkg.com/axios/dist/axios.min.js" rel="external nofollow" ></script>
GET
请求
// 为给定 ID 的 user 创建请求
axios.get("/user?ID=12345")
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
});
// 上面的请求也可以这样做
axios.get("/user", {
params: {
ID: 12345
}
})
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
});
POST
请求
axios.post("/user", {
firstname: "Fred",
lastName: "Flintstone"
})
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
});
function getUserAccount () {
return axios.get("/user/12345");
}
function getUserPermissions () {
return axios.get("/user/12345/permissions");
}
axios.all([getUserAccount(), getUserPermission()])
.then(axios.spread(function (acct, perms) {
// 两个请求都执行完成
}));
xAxis.min |number, string, function[ default: null ]坐标轴刻度最小值。可以设置成特殊值'dataMin',此时取数据在该...
Highcharts 双轴车速表Highcharts 测量图以下实例演示了双轴车速表。我们在前面的章节已经了解了 Highcharts 基本配置语法。接下...
Highcharts 堆叠3D柱形图Highcharts 3D图以下实例演示了堆叠3D柱形图。我们在前面的章节已经了解了 Highcharts 基本配置语法。接...
Angular包格式本文档描述了Angular包格式(APF)。APF是针对npm包结构和格式的Angular专用规范,所有第一方Angular包(@angular/...
准备从AngularJS升级注意:本指南仅仅适用于从AngularJS升级和注重性能的升级。本指南中提到的升级指南使用的是已弃用的快速上手...
AngularJS 动画AngularJS 提供了动画效果,可以配合 CSS 使用。AngularJS 使用动画需要引入 angular-animate.min.js 库。script ...
在模板中绑定表达式是非常便利的,但是它们实际上只用于简单的操作。在模板中放入太多的逻辑会让模板过重且难以维护。例如:div ...
声明文件原理:深入探究组织模块以提供你想要的API形式保持一致是比较难的。 比如,你可能想要这样一个模块,可以用或不用new来...
1. Promise 的含义Promise 是异步编程的一种解决方案,比传统的解决方案——回调函数和事件——更合理和更强大。它由社区最早提...
本节介绍在javascript中,JSON对象与JSON字符串是如何相互转换的。接下来请看相关代码:代码如下:htmlheadmeta http-equiv="Cont...