Skip to content

Latest commit

 

History

History
44 lines (34 loc) · 713 Bytes

状态管理.md

File metadata and controls

44 lines (34 loc) · 713 Bytes

状态管理

redux + dva

如何新建一个model

新建一个model

import { fetchDataAPI } from '~/services/xxx'

  export default {
   namespace: 'testNsp',
   state: {
       item: [],
   },
   effects: {
      *fetchItemsGenerator(params, { call, put }) {
        const items = yield call(fetchDataAPI, params)
        put({ type: 'setItems', payload: items })
   },

   },
   reducers: {
       setItems(state, { payload: items }) {
           return {
               ...state,
              items
           };
       },
   },
};

然后手动注册model

  import test from './test';
  export const registerModels = app => {
  app.model(test)
};