docs: fix missing @/services/product (#34003)

* docs: fix missing @/services/product

close #33952

* update data
This commit is contained in:
afc163 2022-02-10 18:24:53 +08:00 committed by GitHub
parent dc67fd7dbb
commit c3f8568620
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 56 additions and 2 deletions

View File

@ -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';

View File

@ -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';