vue请求失败自动重试

 

/* 统一请求包装:网络/HTTP 层报错时 300ms 后自动重试 1 次;仍失败则按原失败分支处理(业务 success=false 不重试) */
postRetry (url, params) {
  return this.$http.post(url, params).catch(() => {
    return new Promise((resolve, reject) => {
      setTimeout(() => {
        this.$http.post(url, params).then(resolve, reject)
      }, 300)
    })
  })
}

 

posted @ 2026-11-06 09:41  君子笑而不语  阅读(2)  评论(0)    收藏  举报