能够提供自动完成和参数类型推断功能
17 | ```
18 |
19 | # 用例
20 |
21 | 发起一个 `GET` 请求
22 |
23 | ```js
24 | const axios = require('axios');
25 |
26 | // 向给定ID的用户发起请求
27 | axios.get('/user?ID=12345')
28 | .then(function (response) {
29 | // 处理成功情况
30 | console.log(response);
31 | })
32 | .catch(function (error) {
33 | // 处理错误情况
34 | console.log(error);
35 | })
36 | .finally(function () {
37 | // 总是会执行
38 | });
39 |
40 | // 上述请求也可以按以下方式完成(可选)
41 | axios.get('/user', {
42 | params: {
43 | ID: 12345
44 | }
45 | })
46 | .then(function (response) {
47 | console.log(response);
48 | })
49 | .catch(function (error) {
50 | console.log(error);
51 | })
52 | .finally(function () {
53 | // 总是会执行
54 | });
55 |
56 | // 支持async/await用法
57 | async function getUser() {
58 | try {
59 | const response = await axios.get('/user?ID=12345');
60 | console.log(response);
61 | } catch (error) {
62 | console.error(error);
63 | }
64 | }
65 | ```
66 |
67 | > **注意:** 由于`async/await` 是ECMAScript 2017中的一部分,而且在IE和一些旧的浏览器中不支持,所以使用时务必要小心。
--------------------------------------------------------------------------------
/posts/zh/handling_errors.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: '错误处理'
3 | prev_title: '拦截器'
4 | prev_link: '/zh/docs/interceptors'
5 | next_title: '取消请求'
6 | next_link: '/zh/docs/cancellation'
7 | ---
8 |
9 | ```js
10 | axios.get('/user/12345')
11 | .catch(function (error) {
12 | if (error.response) {
13 | // 请求成功发出且服务器也响应了状态码,但状态代码超出了 2xx 的范围
14 | console.log(error.response.data);
15 | console.log(error.response.status);
16 | console.log(error.response.headers);
17 | } else if (error.request) {
18 | // 请求已经成功发起,但没有收到响应
19 | // `error.request` 在浏览器中是 XMLHttpRequest 的实例,
20 | // 而在node.js中是 http.ClientRequest 的实例
21 | console.log(error.request);
22 | } else {
23 | // 发送请求时出了点问题
24 | console.log('Error', error.message);
25 | }
26 | console.log(error.config);
27 | });
28 | ```
29 |
30 | 使用 `validateStatus` 配置选项,可以自定义抛出错误的 HTTP code。
31 |
32 | ```js
33 | axios.get('/user/12345', {
34 | validateStatus: function (status) {
35 | return status < 500; // 处理状态码小于500的情况
36 | }
37 | })
38 | ```
39 |
40 | 使用 `toJSON` 可以获取更多关于HTTP错误的信息。
41 |
42 | ```js
43 | axios.get('/user/12345')
44 | .catch(function (error) {
45 | console.log(error.toJSON());
46 | });
47 | ```
48 |
--------------------------------------------------------------------------------
/posts/zh/instance.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: 'Axios 实例'
3 | prev_title: 'Axios API'
4 | prev_link: '/zh/docs/api_intro'
5 | next_title: '请求配置'
6 | next_link: '/zh/docs/req_config'
7 | ---
8 |
9 | ### 创建一个实例
10 |
11 | 您可以使用自定义配置新建一个实例。
12 |
13 | ##### axios.create([config])
14 |
15 | ```js
16 | const instance = axios.create({
17 | baseURL: 'https://some-domain.com/api/',
18 | timeout: 1000,
19 | headers: {'X-Custom-Header': 'foobar'}
20 | });
21 | ```
22 |
23 | ### 实例方法
24 |
25 | 以下是可用的实例方法。指定的配置将与实例的配置合并。
26 |
27 | ##### axios#request(config)
28 | ##### axios#get(url[, config])
29 | ##### axios#delete(url[, config])
30 | ##### axios#head(url[, config])
31 | ##### axios#options(url[, config])
32 | ##### axios#post(url[, data[, config]])
33 | ##### axios#put(url[, data[, config]])
34 | ##### axios#patch(url[, data[, config]])
35 | ##### axios#getUri([config])
--------------------------------------------------------------------------------
/posts/zh/interceptors.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: '拦截器'
3 | prev_title: '默认配置'
4 | prev_link: '/zh/docs/config_defaults'
5 | next_title: '错误处理'
6 | next_link: '/zh/docs/handling_errors'
7 | ---
8 |
9 | 在请求或响应被 then 或 catch 处理前拦截它们。
10 |
11 | ```js
12 | // 添加请求拦截器
13 | axios.interceptors.request.use(function (config) {
14 | // 在发送请求之前做些什么
15 | return config;
16 | }, function (error) {
17 | // 对请求错误做些什么
18 | return Promise.reject(error);
19 | });
20 |
21 | // 添加响应拦截器
22 | axios.interceptors.response.use(function (response) {
23 | // 2xx 范围内的状态码都会触发该函数。
24 | // 对响应数据做点什么
25 | return response;
26 | }, function (error) {
27 | // 超出 2xx 范围的状态码都会触发该函数。
28 | // 对响应错误做点什么
29 | return Promise.reject(error);
30 | });
31 | ```
32 |
33 | 如果你稍后需要移除拦截器,可以这样:
34 |
35 | ```js
36 | const myInterceptor = axios.interceptors.request.use(function () {/*...*/});
37 | axios.interceptors.request.eject(myInterceptor);
38 | ```
39 |
40 | 可以给自定义的 axios 实例添加拦截器。
41 |
42 | ```js
43 | const instance = axios.create();
44 | instance.interceptors.request.use(function () {/*...*/});
45 | ```
--------------------------------------------------------------------------------
/posts/zh/notes.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: '注意事项'
3 | description: '一些注意事项'
4 | prev_title: 'Multipart 实体请求'
5 | prev_link: '/zh/docs/multipart'
6 | ---
7 |
8 | ## 语义化
9 | 在axios达到 `1.0` 版本之前,破坏性更改将以新的次要版本发布。 例如 `0.5.1` 和 `0.5.4` 将具有相同的 API,但 `0.6.0` 将具有重大变化。
10 |
11 | ## Promises
12 |
13 | axios 依赖原生的ES6 Promise实现而[被支持](http://caniuse.com/promises)。
14 | 如果你的环境不支持 ES6 Promise,你可以使用[polyfill](https://github.com/jakearchibald/es6-promise)。
15 |
16 | ## TypeScript
17 | axios 包含 [TypeScript](http://typescriptlang.org) 类型定义。
18 | ```typescript
19 | import axios from 'axios';
20 | axios.get('/user?ID=12345');
21 | ```
22 |
23 | ## 资源
24 |
25 | * [变更日志](https://github.com/axios/axios/blob/master/CHANGELOG.md)
26 | * [升级指南](https://github.com/axios/axios/blob/master/UPGRADE_GUIDE.md)
27 | * [生态系统](https://github.com/axios/axios/blob/master/ECOSYSTEM.md)
28 | * [贡献指南](https://github.com/axios/axios/blob/master/CONTRIBUTING.md)
29 | * [行为准则](https://github.com/axios/axios/blob/master/CODE_OF_CONDUCT.md)
30 |
31 | ## Credits
32 |
33 | axios 深受[Angular](https://angularjs.org/)提供的[$http service](https://docs.angularjs.org/api/ng/service/$http)的启发。
34 | 最终,axios提供了一个独立的类似于 `$http` 的服务,以便在Angular之外使用。
35 |
36 | ## 许可证
37 |
38 | [MIT](https://github.com/axios/axios/blob/master/LICENSE)
--------------------------------------------------------------------------------
/posts/zh/res_schema.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: '响应结构'
3 | prev_title: '请求配置'
4 | prev_link: '/zh/docs/req_config'
5 | next_title: '默认配置'
6 | next_link: '/zh/docs/config_defaults'
7 | ---
8 |
9 | 一个请求的响应包含以下信息。
10 |
11 | ```js
12 | {
13 | // `data` 由服务器提供的响应
14 | data: {},
15 |
16 | // `status` 来自服务器响应的 HTTP 状态码
17 | status: 200,
18 |
19 | // `statusText` 来自服务器响应的 HTTP 状态信息
20 | statusText: 'OK',
21 |
22 | // `headers` 是服务器响应头
23 | // 所有的 header 名称都是小写,而且可以使用方括号语法访问
24 | // 例如: `response.headers['content-type']`
25 | headers: {},
26 |
27 | // `config` 是 `axios` 请求的配置信息
28 | config: {},
29 |
30 | // `request` 是生成此响应的请求
31 | // 在node.js中它是最后一个ClientRequest实例 (in redirects),
32 | // 在浏览器中则是 XMLHttpRequest 实例
33 | request: {}
34 | }
35 | ```
36 |
37 | 当使用 `then` 时,您将接收如下响应:
38 |
39 | ```js
40 | axios.get('/user/12345')
41 | .then(function (response) {
42 | console.log(response.data);
43 | console.log(response.status);
44 | console.log(response.statusText);
45 | console.log(response.headers);
46 | console.log(response.config);
47 | });
48 | ```
49 |
50 | 当使用 `catch`,或者传递一个[rejection callback](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/then)作为 `then` 的第二个参数时,响应可以通过 `error` 对象被使用,正如在[错误处理](/zh/docs/handling_errors)部分解释的那样。
--------------------------------------------------------------------------------
/posts/zh/translating.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: '翻译文档'
3 | ---
4 |
5 | 为了让Axios被尽可能多的人所了解,将文档翻译成多种语言是必要的。我们对想要帮助翻译文档的人表示衷心的感谢。本文给出了向文档添加翻译的指南。
6 |
7 | ## 结构
8 |
9 | 每种语言的翻译都由一个配置文件`{language-shortcut}.lang.js`(例如,`en.lang.js`或者`de.lang.js`),以及一些翻译后的文档文件组成`posts/{language-shortcut}/*.md`(例如`posts/en`或者`posts/de`)。`{language-shortcut}`应该用你所使用的语言的[ISO 639-1](https://en.wikipedia.org/wiki/ISO_639-1)双字母代号替换。
10 |
11 | ## 编写配置文件
12 |
13 | - 创建一个`en.lang.js`文件的副本。
14 | - 将副本重命名为`{language-shortcut}.lang.js`并对副本文件内容做出以下修改。
15 | - 将`display`字段替换为你所使用的语言的名字,用该种语言的文字来书写。例如,如果你想将文档翻译成德语,应该在该字段填写“Deutsch”而不是“German”。
16 | - 将`prefix`字段替换为`/{language-shortcut}/`。
17 | - 翻译`p`字段以及`t`字段中的values部分,不要翻译keys。
18 | - 翻译所有`sidebar`字段里标签为`text`的属性。**注意:**从文档的当前版本开始,sidebar里的链接部分已经不需要再更新了。
19 |
20 | ### 注册配置文件
21 |
22 | 当你编写完了配置文件后,你需要在项目配置文件里注册该配置。你需要打开`inert.config.js`文件并且在接近顶部的位置添加下面这一行代码:
23 |
24 | ```js
25 | const {language-shortcut}Config = require('./{language-shortcut}.config.js');
26 | ```
27 |
28 | 当然,别忘了将上面这行代码的`{language-shortuct}`部分替换成你所使用语言的[ISO 639-1](https://en.wikipedia.org/wiki/ISO_639-1)双字母代号。
29 |
30 | 现在,找到该文件的`langs`常量。如果该常量的声明在你的`require`语句之前,请将你的`require`语句移至该常量声明之前。对于`langs`列表,你需要添加如下这个对象:
31 |
32 | ```js
33 | const langs = [
34 | ...
35 | {
36 | name: 'Some name that uniquely identifies your language, for example "English" or "German"',
37 | prefix: "The same prefix as in the configuration file",
38 | config: {language-shortcut}Config // The configuration object you imported earlier
39 | }
40 | ...
41 | ];
42 | ```
43 |
44 | 现在,你可以开始翻译文档了。将`posts/en`文件夹复制到一个新文件夹`posts/{language-shortcut}`,翻译这个新文件夹下的所有文件(保持文件名不变,只翻译文件内容)。
45 |
46 | 如果你遇到了任何问题,欢迎前来[提出问题](https://github.com/axios/axios-docs/issues/new/choose)。
47 |
--------------------------------------------------------------------------------
/scss/home_variables.scss:
--------------------------------------------------------------------------------
1 | :root {
2 | --primary-color: #5A29E4;
3 | --primary-shadow-color: #5b29e45d;
4 | --secondary-color: #D442C6;
5 | --fg-color: #1f1c24;
6 | --margin: 60px;
7 | --font-sans: 'DM Sans', sans-serif;
8 | --font-mono: 'DM Mono', monospace;
9 | --fw-light: 300;
10 | --fw-regular: 400;
11 | --fw-medium: 500;
12 | --fw-semibold: 600;
13 | --fw-bold: 700;
14 | --fw-extrabold: 800;
15 | --fw-black: 900;
16 | font-size: 5px;
17 | }
18 |
19 | @media screen and (min-width: 370px) {
20 | :root {
21 | font-size: 7px;
22 | }
23 | }
24 |
25 | @media screen and (min-width: 500px) {
26 | :root {
27 | font-size: 10px;
28 | }
29 | }
30 |
31 | @media screen and (min-width: 1000px) {
32 | :root {
33 | --margin: 25vw;
34 | }
35 |
36 | .code-preview {
37 | display: block !important;
38 | }
39 |
40 | section#hero {
41 | div.content {
42 | width: 60% !important;
43 | }
44 | }
45 | }
--------------------------------------------------------------------------------
/scss/post.scss:
--------------------------------------------------------------------------------
1 | li.sponsor-card {
2 |
3 | width: calc(15%);
4 |
5 | /* &[data-has-logo=true] .caption {
6 | display: none;
7 | }*/
8 |
9 | &[data-tier=gold] {
10 | width: calc(25%);
11 | }
12 |
13 | &[data-tier=platinum] {
14 | width: calc(33%);
15 | }
16 | }
17 |
18 | .body {
19 | table{
20 | border-collapse: collapse;
21 | width: 100%;
22 | }
23 |
24 | table,th,td{
25 | border: 1px solid #1f1c24;
26 | padding: 3px;
27 | }
28 | }
29 |
30 | blockquote{
31 | border-left: 5px solid var(--primary-color);
32 | margin-left: 1rem;
33 |
34 | > p {
35 | padding: 10px;
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/scss/variables.scss:
--------------------------------------------------------------------------------
1 | :root {
2 | --primary-color: #671ddf;
3 |
4 | --col-black: #373747;
5 |
6 | --col-bg: #ffffff;
7 | --col-fg: var(--col-black);
8 |
9 | --gray-2: #edf2f6;
10 | --gray-3: #dbe1e6;
11 |
12 | --max-contrast: #000000;
13 |
14 | /* Shadows */
15 | --shadow-blue-light: 0px 10px 20px rgba(var(--col-blue-rgb), 0.6);
16 | --shadow-blue-dark: 0px 10px 20px rgba(var(--col-blue-rgb), 0.2);
17 |
18 | --shadow-blue: var(--shadow-blue-light);
19 |
20 | /* Delays */
21 | --transition-delay: 0ms;
22 |
23 |
24 | }
25 |
26 | body.dark {
27 | --primary-color: #cdcdcd;
28 |
29 | --col-bg: var(--col-black);
30 | --col-fg: #cdcdcd;
31 |
32 | --gray-2: #434358;
33 | --gray-3: #505063;
34 |
35 | --max-contrast: #ffffff;
36 |
37 | --shadow-blue: var(--shadow-blue-dark);
38 | }
39 |
--------------------------------------------------------------------------------
/templates/sponsors.hbs:
--------------------------------------------------------------------------------
1 | {{#if sponsors}}
2 |
3 | {{caption}}
4 |
5 |
6 |
7 | {{#table sponsors cells separate fill}}
8 | {{#if this}}
9 | {{#if displayName}}
10 | {{#if image}}
11 |
12 | {{#if image_dark}}
13 |
14 |
15 |
16 |
17 | {{else}}
18 |
19 | {{/if}}
20 |
21 | {{else}}
22 | {{displayName}}
23 | {{/if}}
24 | {{#if description}}{{#short benefits.maxReadmeDescLength}}{{description}}{{/short}}
{{else}}{{#if showCaptions}}{{displayName}}
{{/if}}{{/if}}
25 | {{#if links}}
26 | {{#each links}}{{#short 40}}{{@key}}{{/short}}{{#sep}} | {{/sep}}{{/each}}
27 |
{{/if}}
28 | {{else}}
29 | - {{displayName}}
30 | {{/if}}
31 | {{else}}
32 | 💜 Become a sponsor
33 | {{/if}}
34 | {{/table}}
35 | {{/if}}
36 |
--------------------------------------------------------------------------------