ant-design-pro3.x dva

记录一知识点:关于ant-design-pro dva 的使用

先看先官方粑粑的解释

effects异步请求服务器数据
reducers缓存请求数据
reducers的存入数据:
/* eslint-disable @typescript-eslint/camelcase */
import Service from '@/services/service';

export default {
  namespace: 'shopProductCategory',
  state: {
    categories: [],
  },
  effects: {
    *pullCategoryLists({ payload, callback }, { call, put }) {
      const listsApi = new Service('product-shop-product-category-lists');
      const { status, data, total, text } = yield call(listsApi.PostData, payload, 'all');
      yield put({
        type: 'dataList',
        payload: { categories: data || [] },
      });
      callback({ status, data, total, text }, () => { });
    },
  },

  reducers: {
    dataList(state, { payload }) {
      const nstate = {
        ...state,
        ...payload,
      };
      return nstate;
    },
  },
};

使用数据

const {
    shopProductCategory: { categories },
} = this.props;

 

posted @ 2021-07-31 15:12  TaurusBoy  阅读(139)  评论(0)    收藏  举报