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);
    }


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM