DvaJS model 入参使用解构

import * as usersService from '../services/users';

export default {
  namespace: 'users',
  state: {
    list: [],
    total: null,
  },
  reducers: {
    save(state, { payload: { data: list, total } }) {
      return { ...state, list, total };
    },
  },
  effects: {
    *fetch({ payload: { page } }, { call, put }) {
      const { data, headers } = yield call(usersService.fetch, { page });
      yield put({ type: 'save', payload: { data, total: headers['x-total-count'] } });
    },
  },
  subscriptions: {
    setup({ dispatch, history }) {
      return history.listen(({ pathname, query }) => {
        if (pathname === '/users') {
          dispatch({ type: 'fetch', payload: query });
        }
      });
    },
  },
};
save(state, { payload: { data: list, total } }) 和 *fetch({ payload: { page } }, { call, put }) 入参用了解构,这个还是第一次碰到,记录下来方便以后工作查找,以便代码优化。
posted @ 2021-05-17 16:11  尖子  阅读(228)  评论(0编辑  收藏  举报