dva.js的dispatch的回调
在dva@2中实现回调可以将回调函数作为参数dispatch:
dispatch({ type: 'model/fetch', payload: { resolve, id: userId, }, callback: res => { console.log(res); } })
然后在model的effects中这样写:
*fetch({ payload, callback }, {call}) {
const response = yield call(services.fetch, payload);
if (response.code === 0) {
yield put({
type: 'reload',
payload: response,
});
if (callback) callback(response);
}
posted on 2021-09-22 18:13 Hhhhhhhhii 阅读(498) 评论(0) 编辑 收藏 举报