redux + dva
新建一个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)
};