how to cancel/abort ajax request in axios

前端 未结 8 695
广开言路
广开言路 2020-12-05 06:19

I use axios for ajax requests and reactJS + flux for render UI. In my app there is third side timeline (reactJS component). Timeline c

8条回答
  •  爱一瞬间的悲伤
    2020-12-05 06:48

    Axios does not support canceling requests at the moment. Please see this issue for details.

    UPDATE: Cancellation support was added in axios v0.15.

    EDIT: The axios cancel token API is based on the withdrawn cancelable promises proposal.

    Example:

    const cancelTokenSource = axios.CancelToken.source();
    
    axios.get('/user/12345', {
      cancelToken: cancelTokenSource.token
    });
    
    // Cancel request
    cancelTokenSource.cancel();
    

提交回复
热议问题