利用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;
	})

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

export const getWFSItemByEventApi = (params, othrer) => {
  return http.request<ResultType>({
    url: "/cupCommonApi/cup-emergency/eventresource/getWFSItemByEvent",
    method: "post",
    data: params,
    ...othrer,
  });
};

3.取消请求

 // 删除图层
  layerName__controller[data.layerName]?.abort();

相关推荐

  1. s AbortController 接口取消多次请求 取消上次请求

    2024-04-12 17:14:01       31 阅读
  2. 使用【AbortController】终止请求

    2024-04-12 17:14:01       31 阅读
  3. AI取代程序猿?

    2024-04-12 17:14:01       26 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-04-12 17:14:01       98 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-04-12 17:14:01       106 阅读
  3. 在Django里面运行非项目文件

    2024-04-12 17:14:01       87 阅读
  4. Python语言-面向对象

    2024-04-12 17:14:01       96 阅读

热门阅读

  1. C 头文件

    2024-04-12 17:14:01       38 阅读
  2. WHAT - 二叉树系列(六)

    2024-04-12 17:14:01       33 阅读
  3. C++ std::string 和std::map实现原理

    2024-04-12 17:14:01       34 阅读
  4. .NET 设计模式—享元模式(Flyweight Pattern)

    2024-04-12 17:14:01       47 阅读
  5. Android音视频开发-AudioRecord

    2024-04-12 17:14:01       38 阅读
  6. MySQl的 ResultSet

    2024-04-12 17:14:01       39 阅读
  7. 红黑树-B B- B+树总结

    2024-04-12 17:14:01       46 阅读
  8. 偌依框架的分页失效改用手动作分页

    2024-04-12 17:14:01       197 阅读