react中用了async就不用redux-thunk这个插件了吧?

export const getMenu = () => {
  return async (dispatch) => {
    let msg = await fetch('data/nodes',{
      method: 'POST',
      //body: JSON.stringify({"aa":"aa"}),
      header: {'content-type':'application/json; charset=utf-8'}
    }).then((res)=>res.json());
    var state = { nodes: msg };
    dispatch({
      type: 'INIT',
      state
    });
  };
}
阅读 2.5k
1 个回答

但是你这样写还是需要的,redux-thunk就是支持Function Action。

这种你想在ActionCreator 中自己dispatch,还是要用这种方法。

如果你的Action诗歌Promise,你可以换成 redux-promise,他会自动帮你dispatch resolve后的值。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题