-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
|
||
.normal { | ||
} | ||
|
||
.operation a { | ||
margin: 0 .5em; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { connect } from 'dva'; | ||
import { Table, Pagination, Popconfirm } from 'antd'; | ||
import styles from './Users.css'; | ||
import { PAGE_SIZE } from '../constants'; | ||
|
||
function Users({ list: dataSource, total, page: current }) { | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
Jeff-Tian
|
||
function deleteHandler(id) { | ||
console.warn(`TODO: ${id}`); | ||
} | ||
|
||
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', | ||
}, | ||
{ | ||
title: 'Operation', | ||
key: 'operation', | ||
render: (text, { id }) => ( | ||
<span className={styles.operation}> | ||
<a href="">Edit</a> | ||
<Popconfirm title="Confirm to delete?" onConfirm={deleteHandler.bind(null, id)}> | ||
<a href="">Delete</a> | ||
</Popconfirm> | ||
</span> | ||
), | ||
}, | ||
]; | ||
|
||
return ( | ||
<div className={styles.normal}> | ||
<div> | ||
<Table | ||
columns={columns} | ||
dataSource={dataSource} | ||
rowKey={record => record.id} | ||
pagination={false} | ||
/> | ||
<Pagination | ||
className="ant-table-pagination" | ||
total={total} | ||
current={current} | ||
pageSize={PAGE_SIZE} | ||
/> | ||
</div> | ||
</div> | ||
); | ||
} | ||
|
||
function mapStateToProps(state) { | ||
const { list, total, page } = state.users; | ||
return { | ||
list, | ||
total, | ||
page, | ||
}; | ||
} | ||
|
||
export default connect(mapStateToProps)(Users); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
|
||
export const PAGE_SIZE = 3; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
import Users from './components/Users'; | ||
|
||
export default () => { | ||
return ( | ||
<div> | ||
Users Page | ||
<Users /> | ||
</div> | ||
) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
import { PAGE_SIZE } from '../constants'; | ||
import request from '../../../utils/request'; | ||
|
||
export function fetch({ page = 1 }) { | ||
return request(`/api/users?_page=${page}&_limit=5`); | ||
return request(`/api/users?_page=${page}&_limit=${PAGE_SIZE}`); | ||
} |
6 comments
on commit ee9ccba
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
为啥 我导入 组件后 报错:TypeError: Cannot read property 'list' of undefined
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我也是
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
什么鬼教程,完全看不懂;
到底是 dva 的项目,还是 umi 的项目,结构目录完全不同
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
为啥 我导入 组件后 报错:TypeError: Cannot read property 'list' of undefined
需要在index.js里加入model,否则就看不到models/users.js里的任何变量
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
需要有点基础的来看,教程没问题。思路很清晰
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
什么鬼教程,完全看不懂;
到底是 dva 的项目,还是 umi 的项目,结构目录完全不同
同意。国产框架不错,文档不行。
这文档太垃圾了, 跟着文档完全就做不出来
list: dataSource 是什么意思啊