代码之家  ›  专栏  ›  技术社区  ›  Joseph

在React中从API获取加载器状态

  •  0
  • Joseph  · 技术社区  · 4 年前

    我有一个名为的方法 getInfo ,我曾经向API请求使用 POST 方法我的问题是,我也想得到图像加载的百分比。我正在使用 axios 而且

    export const getInfo = () => async (dispatch) => {
      try {
        dispatch({
          type: constants.requesting,
        });
    
        const response = await axios.post(`https://test.com`, null);
        console.log(response);
        dispatch({
          type: constants.success,
        });
      } catch (error) {
        console.log(error);
        dispatch({
          type: constants.error,
        });
      }
    };
    
    0 回复  |  直到 4 年前