Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: fix missing @/services/product #34003

Merged
merged 2 commits into from Feb 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 28 additions & 1 deletion docs/react/practical-projects.en-US.md
Expand Up @@ -100,7 +100,34 @@ export default ProductList;

The file name corresponds to the name of the final model, and you can consume the data in the model through the API provided by the plug-in.

Let's take a simple table as an example. First you need to create a new file `src/models/useProductList.ts`.
Let's take a simple table as an example. First we create a new file `src/services/product.ts` for remote API.

```tsx
/*
export function queryProductList() {
return fetch('/api/products').then(res => res.json());
}
*/
// mock request service by setTimeout
export function queryProductList() {
return new Promise(resolve => {
setTimeout(() => {
resolve([
{
id: 1,
name: 'dva',
},
{
id: 2,
name: 'antd',
},
]);
}, 2000);
});
}
```

Then you need to create a new file `src/models/useProductList.ts`.

```tsx
import { useRequest } from 'umi';
Expand Down
29 changes: 28 additions & 1 deletion docs/react/practical-projects.zh-CN.md
Expand Up @@ -97,7 +97,34 @@ export default ProductList;

文件名则对应最终 model 的 name,你可以通过插件提供的 API 来消费 model 中的数据。

我们以一个简单的表格作为示例。首先需要新建文件 `src/models/useProductList.ts`。
我们以一个简单的表格作为示例。首先新建一个 `src/services/product.ts` 存放产品相关的接口。

```tsx
/*
export function queryProductList() {
return fetch('/api/products').then(res => res.json());
}
*/
// 先用 setTimeout 模拟一个请求,正常的写法如上所示
export function queryProductList() {
return new Promise(resolve => {
setTimeout(() => {
resolve([
{
id: 1,
name: 'dva',
},
{
id: 2,
name: 'antd',
},
]);
}, 2000);
});
}
```

然后新建文件 `src/models/useProductList.ts`。

```tsx
import { useRequest } from 'umi';
Expand Down