新手入门

基于 Promise 的 HTTP 客户端,适用于浏览器和 node.js

什么是 Axios?

¥What is Axios?

Axios 是一个 基于 promise 的 HTTP 客户端,适用于 node.js 和浏览器。它是 同构的(即它可以使用同一套代码运行在浏览器和 nodejs 中)。在服务器端它使用原生的 node.js http 模块,在客户端(浏览器)它使用 XMLHttpRequests。

¥Axios is a promise-based HTTP Client for node.js and the browser. It is isomorphic (= it can run in the browser and nodejs with the same codebase). On the server-side it uses the native node.js http module, while on the client (browser) it uses XMLHttpRequests.

特性

¥Features

安装

¥Installing

使用 npm:

¥Using npm:

$ npm install axios

使用 bower:

¥Using bower:

$ bower install axios

使用 yarn:

¥Using yarn:

$ yarn add axios

使用 jsDelivr CDN:

¥Using jsDelivr CDN:

<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>

使用 unpkg CDN:

¥Using unpkg CDN:

<script src="https://unpkg.com/axios/dist/axios.min.js"></script>

预构建的 CommonJS 模块用于使用 require 直接导入(如果你的模块打包器无法自动解析它们)

¥Prebuilt CommonJS modules for direct importing with require (if your module bundler failed to resolve them automatically)

const axios = require('axios/dist/browser/axios.cjs'); // browser
const axios = require('axios/dist/node/axios.cjs'); // node