学习dva-cli的一个demo的源码,有一个地方不太明白,为什么number会被转变为string
发布于 7 年前 作者 yeelone 4757 次浏览 来自 问答

这两天在学习dva,在看 https://github.com/zuiidea/antd-admin 的代码。有一个疑问,想问问大家。

   https://github.com/zuiidea/antd-admin/blob/master/src/routes/users/index.js
    const userListProps = {
    dataSource: list,
    loading,
    pagination,
    location,
    isMotion,
    onPageChange (page) {
     **console.log({
          ...query,
          page: page.current,
          pageSize: page.pageSize,
        })**    //这里输出 为: Object {page: 1, pageSize: 10}   
      const { query, pathname } = location
      dispatch(routerRedux.push({
        pathname,
        query: {
          ...query,
          page: page.current,
          pageSize: page.pageSize,
          current :page.current
        },
      }))
    },
	}
	
	https://github.com/zuiidea/antd-admin/blob/master/src/models/users.js
	 effects: {
    *query ({ payload }, { call, put }) {
      **console.log("payload ", payload)**    //这里输出 为: Object { page: "1", pageSize: "10"}
      const data = yield call(query, parse(payload))
      var page = {
        total: data.body.total ,
        current: parseInt(payload.page,10)    //如果传递过来的数据类型没变的话,我这里也不用转换类型了。
      } 

      if (data) {
        yield put({
          type: 'querySuccess',
          payload: {
            list: data.body.users,
            pagination:page,
          },
        })
      }
    },

捕获.PNG

我就是不太明白,为什么数据类型会被改变了。

回到顶部