【问题标题】:Aurelia cancel a specific requestAurelia 取消特定请求
【发布时间】:2019-04-30 22:01:04
【问题描述】:

有没有办法取消特定请求?我关注this 取消请求,但是如果我有多个请求怎么办,我如何确定我没有取消错误的请求?有没有办法取消特定请求?

目前它是这样工作的:

async getEmployeeListBySearchword(searchword: string): Promise<IMember[]> {
    try {
        const response = await this.get(`employees/${decodeURIComponent(searchword)}`);
        return JSON.parse(response['response']) as Promise<IMember[]>;
    }catch(e){
        if(e.responseType != "abort") {
            console.log(e);
        }
    }
}

cancelRequest(){
    if(AbortableHttpService.http){
        AbortableHttpService.http['pendingRequests'].forEach(request =>{
            request.abort();
        });
    }
}

http 设置代码被包装在一个名为 AbortableHttpService 的类中,它创建并配置 HttpClient 并为其隐藏一些样板代码。

【问题讨论】:

    标签: aurelia


    【解决方案1】:

    我不确定这是否记录在案,但在 aurelia-http-client 源代码中,我看到一个 cancel/abort 函数被添加到您在发出请求时收到的承诺中。

    所以调用response.cancel()response.abort() 应该可以工作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-11-05
      • 1970-01-01
      • 1970-01-01
      • 2020-05-17
      • 1970-01-01
      • 2017-11-06
      • 2017-05-19
      相关资源
      最近更新 更多