js取消请求的另类方法

2022-09-21  本文已影响0人  Coder_JdHo
xxxRequestId: 1,  //在data中定义请求id变量

///在请求方法中校验当前的id是否等于最新id,非最新的不处理返回的数据
getData() {
   this.xxxRequestId++
   let currentId = this.xxxRequestId
   const res = await service.getData(param)
   if (currentId != this.xxxRequestId) {
     return
   }
   //其他业务代码
}
上一篇 下一篇

猜你喜欢

热点阅读