Skip to content

Commit 5f9cd32

Browse files
hateonionQC-L
authored andcommitted
docs(cn): translate docs/faq-ajax.md into Chinese (#157)
1 parent eb5a97e commit 5f9cd32

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

content/docs/faq-ajax.md

+10-10
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,19 @@ layout: docs
66
category: FAQ
77
---
88

9-
### How can I make an AJAX call? {#how-can-i-make-an-ajax-call}
9+
### 如何在 React 中发起 AJAX 请求?{#how-can-i-make-an-ajax-call}
1010

11-
You can use any AJAX library you like with React. Some popular ones are [Axios](https://github.com/axios/axios), [jQuery AJAX](https://api.jquery.com/jQuery.ajax/), and the browser built-in [window.fetch](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API).
11+
在 React 开发中,你能使用任何你喜欢的 AJAX 库,比如社区比较流行的 [Axios](https://github.com/axios/axios)[jQuery AJAX](https://api.jquery.com/jQuery.ajax/),或者是浏览器内置的 [window.fetch](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API)
1212

13-
### Where in the component lifecycle should I make an AJAX call? {#where-in-the-component-lifecycle-should-i-make-an-ajax-call}
13+
### 应该在 React 组件的哪个生命周期函数中发起 AJAX 请求?{#where-in-the-component-lifecycle-should-i-make-an-ajax-call}
1414

15-
You should populate data with AJAX calls in the [`componentDidMount`](/docs/react-component.html#mounting) lifecycle method. This is so you can use `setState` to update your component when the data is retrieved.
15+
我们推荐你在 [`componentDidMount`](/docs/react-component.html#mounting) 这个生命周期函数中发起 AJAX 请求。这样做你可以拿到 AJAX 请求返回的数据并通过 `setState` 来更新组件。
1616

17-
### Example: Using AJAX results to set local state {#example-using-ajax-results-to-set-local-state}
17+
### 示例:使用 AJAX 请求结果去改变组件内部 state {#example-using-ajax-results-to-set-local-state}
1818

19-
The component below demonstrates how to make an AJAX call in `componentDidMount` to populate local component state.
19+
下面这个组件演示了如何在 `componentDidMount` 中发起 AJAX 请求去更新组件的 state
2020

21-
The example API returns a JSON object like this:
21+
示例 API 返回如下的 JSON 对象:
2222

2323
```
2424
{
@@ -50,9 +50,9 @@ class MyComponent extends React.Component {
5050
items: result.items
5151
});
5252
},
53-
// Note: it's important to handle errors here
54-
// instead of a catch() block so that we don't swallow
55-
// exceptions from actual bugs in components.
53+
// 注意:需要在此处处理错误
54+
// 而不是使用 catch() 去捕获错误
55+
// 因为使用 catch 去捕获异常会掩盖掉组件本身可能产生的 bug
5656
(error) => {
5757
this.setState({
5858
isLoaded: true,

0 commit comments

Comments
 (0)