react+antdesign

121 阅读1分钟

UI层

dispatch({
    type: 'listTableList/fetch',
    payload: {id:id}, //一般作为参数含义,由UI层通过dispatch一个payload参数在model文件中使用
});

model.js主要用来数据和逻辑

const Model = {
    namespace: 'listTableList',
    state:{
        ...//在每一个model中定义state,用于分模块管理全局状态
    },
    effects:{
        * fetch({ payload }, { call, put }) {
            const response = yield call(queryRule, payload);
            yield put({
                type: 'save',
                payload: response,
            });
            return response;
        },
    },
    reducers: {
        save(state, action) {
            return {...state, data: action.payload };
        },
    }
}

service.js

export async function queryRule(params) {
    return request('/api/usersTable', {
        params,
    });
}