dva的dispatch回撥,effects返回請求引數
阿新 • • 發佈:2018-12-09
// 業務中的請求 const params = { /* 引數 */ } new Promise((resolve) => { this.props.dispatch({ type: 'GiftRequest/changeGiftState', payload: { resolve, data: params, } }) }).then((res) => { if (res.code === 200) { notification.success({ message: '操作成功', }); /* do something */ } else { notification.error({ message: res.msg, }); } })
// 在model中的effects
...
namespace: "GiftRequest",
...
*changeGiftState({ payload, query }, { call, put }){
const { resolve } = payload;
const response = yield call(***介面**, payload.data, query);
!!resolve && resolve(response);
},
...