Skip to content

Commit

Permalink
9. Handle page change
Browse files Browse the repository at this point in the history
  • Loading branch information
sorrycc committed Dec 19, 2016
1 parent e256165 commit b6203ea
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/components/Users/Users.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
import React from 'react';
import { connect } from 'dva';
import { Table, Pagination, Popconfirm } from 'antd';
import { routerRedux } from 'dva/router';
import styles from './Users.css';
import { PAGE_SIZE } from '../../constants';

This comment has been minimized.

Copy link
@nsuedu

nsuedu May 15, 2018


function Users({ list: dataSource, loading, total, page: current }) {
function Users({ dispatch, list: dataSource, loading, total, page: current }) {
function deleteHandler(id) {
console.warn(`TODO: ${id}`);
}

function pageChangeHandler(page) {
dispatch(routerRedux.push({

This comment has been minimized.

Copy link
@LL-wzl

LL-wzl Mar 14, 2018

routerRedux.push这个方法报错哦,Hash history cannot PUSH the same path; a new entry will not be added to the history stack。
改成routerRedux.replace就OK了

pathname: '/users',
query: { page },

This comment has been minimized.

Copy link
@ywzhaiqi

ywzhaiqi Oct 22, 2017

dva v2 需要改为 search: queryString.stringify({ page })

This comment has been minimized.

Copy link
@dreampasssser

dreampasssser Dec 15, 2017

是用search还是query啊?我的加上page后就报错了,然后就做不下去了,今天才又逛到这里来。。。

This comment has been minimized.

Copy link
@lucasyue

lucasyue Dec 19, 2017

遇到报这个错:
Hash history cannot PUSH the same path; a new entry will not be added to the history stack

This comment has been minimized.

Copy link
@mengman2016

mengman2016 Dec 19, 2017

把loaction打印下就知道了

This comment has been minimized.

Copy link
@bj75326

bj75326 Dec 19, 2017

dva v2 model/users 中,路由 subscription 也应改为获取search

setup({dispatch, history}){
  return history.listen((location) => {
    const {pathname, search} = location;
    if(pathname === '/users'){
      dispatch({type: 'fetch', payload: querystring.parse(search.replace(/^[?]*(.*)$/, '$1'))})
    }
  });
},
}));
}

const columns = [
{
title: 'Name',
Expand Down Expand Up @@ -55,6 +63,7 @@ function Users({ list: dataSource, loading, total, page: current }) {
total={total}
current={current}
pageSize={PAGE_SIZE}
onChange={pageChangeHandler}
/>
</div>
</div>
Expand Down

8 comments on commit b6203ea

@DaDaDaDaDaBocai
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

如果数据为空的话,页码没有隐藏,而是有5页,然后有个NaN,请问怎么解决?

@PeterRock
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

在models/users.js中effets的fetch方法中有如下代码:

          total: parseInt(headers['x-total-count'], 10),
          page: parseInt(page, 10),

默认值是10,所以才会出现5页

@littlegirlRachel
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

后面添加了删除功能后只是能够响应,并不能真正在界面上去掉数据,有什么思路呢

@dreampasssser
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

从加入page开始就一直报这个错误:
Error: TypeError: Cannot read property 'page' of undefined.
导致查不出信息,
你们有遇到过吗?

@hangyangws
Copy link

@hangyangws hangyangws commented on b6203ea Nov 17, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dreampasssser 你应该用的 dva 2.0 版本,dva 2.0 不是这么写了。

sorrycc/blog#18 上面有写 注:本文仅适用于 dva@1,尚未适配到 dva@2 。


想知道具体的写法,可以参考:https://github.com/dvajs/dva-example-user-dashboard 代码

@dreampasssser
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hangyangws 确实用的dva2.x版本,没注意到那句话,谢谢啦

@mengman2016
Copy link

@mengman2016 mengman2016 commented on b6203ea Dec 19, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

点击分页报了个错:Warning: Hash history cannot PUSH the same path; a new entry will not be added to the history stack,有人遇到过吗? "dva": "^2.1.0",

@cronaldoyang
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

点击分页报了个错:Warning: Hash history cannot PUSH the same path; a new entry will not be added to the history stack,有人遇到过吗? "dva": "^2.1.0",

同样的报错

Please sign in to comment.