1. 程式人生 > >dva的dispatch回撥,effects返回請求引數

dva的dispatch回撥,effects返回請求引數

// 業務中的請求
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);
},
...