Skip to content

Commit

Permalink
feat: 使用 use-request 请求数据并展示到表格
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivocin committed Feb 26, 2021
1 parent caaf692 commit 6979cbc
Show file tree
Hide file tree
Showing 3 changed files with 1,321 additions and 1 deletion.
1 change: 1 addition & 0 deletions vite-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"serve": "vite preview"
},
"dependencies": {
"@ahooksjs/use-request": "^2.8.3",
"antd": "^4.12.3",
"react": "^17.0.0",
"react-dom": "^17.0.0",
Expand Down
34 changes: 33 additions & 1 deletion vite-react/src/pages/user/index.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,38 @@
import React from 'react'
import './index.css'
import useRequest from '@ahooksjs/use-request'
import { Table } from 'antd'

export default function User(props) {
return <div className="User">User Page</div>
const { data, error, loading } = useRequest('/api/users')

const columns = [
{
title: 'Name',
dataIndex: 'name',
key: 'name',
render: (text) => <a href="">{text}</a>,
},
{
title: 'Email',
dataIndex: 'email',
key: 'email',
},
{
title: 'Website',
dataIndex: 'website',
key: 'website',
},
]
return (
<div className="User">
<Table
size="small"
columns={columns}
dataSource={data}
rowKey={(record) => record.id}
loading={loading}
/>
</div>
)
}
Loading

0 comments on commit 6979cbc

Please sign in to comment.