model( redux )文件中
state
// XxxModel 为 xxxModel 的类型export interface xxxSate{ 数据名1: 类型1, 数据名2: 类型2}interface XxxModel { namespace: string; state : xxxSate}const xxxModel : XxxModel = { namespace: 'xxxModel', state: { 数据名1: 初始数据1, 数据名2: 初始数据2 }}
import { Effect } from 'umi';interface XxxModel { namespace: string; state : xxxSate; effects: { getXxx: Effect }}const xxxModel : XxxModel = { namespace: 'xxxModel', effects: { *getXxx ( { payload }, { put, call } ) { ... } }}
import { Effect , ImmerReducer } from 'umi';import * as services from '@/services';interface XxxModel { namespace: string; state : xxxSate; effects: { getXxx: Effect }; reducers: { GET_XXX: ImmerReducer }}const xxxModel : XxxModel = { namespace: 'xxxModel', effects: { *getXxx ( { 页面传递的参数 }, { put, call } ) { const 请求到的数据 = yield call( services.请求的方法 , 页面传递的参数 ) yield put({ type: "GET_XXX", payload: 请求到的数据 }) } } reducers: { GET_XXX( state , { payload}){ 改变state... } }}