当前位置:   article > 正文

利用AbortController,取消正在发送的请求

利用AbortController,取消正在发送的请求

参考文章:https://blog.csdn.net/qq_45560350/article/details/130588101
解决问题:再图层中点击仓库的时候,点击后又取消掉,我们希望这个请求可以被取消掉,我们口可以利用AbortController控制器对象
在这里插入图片描述
实操:

1.再请求前创造一个构造器

const layerName__controller = {}

 layerName__controller[layerName] = new AbortController();
    getWFSItemByEventApi(params, {
      signal: layerName__controller[layerName].signal,
    }).then(res => {
    
    }).finally(() => {
		 layerName__controller[layerName] = null;
	})
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

2.我们的请求,要在请求体里面添加上这个属性

export const getWFSItemByEventApi = (params, othrer) => {
  return http.request<ResultType>({
    url: "/cupCommonApi/cup-emergency/eventresource/getWFSItemByEvent",
    method: "post",
    data: params,
    ...othrer,
  });
};
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

3.取消请求

 // 删除图层
  layerName__controller[data.layerName]?.abort();
  • 1
  • 2
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/羊村懒王/article/detail/443866
推荐阅读