Wiederholen Sie die Axios-Anfrage, wenn die Antwort leer ist
P粉863295057
P粉863295057 2024-03-19 17:20:54
0
1
264

await axios
    .post(
      executeBatch,
      {
        headers: {
          "Content-Type": "application/json",
          "x-access-token": localStorage.getItem("token"),
        },
      }
    )
    .then(
      (response) =>
        this.$store.commit(
          "insertOutputFile",
          response.data.outputFile._id
        ),
    );

  alert("You can download the result");

Manchmal bekomme ich eine leere Antwort mit dem Statuscode 200, Erwägen Sie in diesem Fall einen erneuten Versuch der Anfrage. Ich möchte wissen, wie man dieses Problem richtig löst.

P粉863295057
P粉863295057

Antworte allen(1)
P粉556159786

我认为 axios 拦截器适合你。

axios.interceptors.response.use((response) => {
    return response
  },
  async function(error) {
    const originalRequest = error.config;

    if () { // condition
      originalRequest._retry = true;
    }
  }
)

您可以在基本 redux 目录中创建 setupAxios 文件,并从基本 redux 目录中的 index.js 导出它。

export {default as setupAxios} from "./setupAxios";

并从根index.js文件定义setupAxios

import * as _redux from "./redux";

_redux.setupAxios(axios, store);

顺便说一句,我使用的是react.js,vue.js 中的它可能有点不同。

Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage
Über uns Haftungsausschluss Sitemap
Chinesische PHP-Website:Online-PHP-Schulung für das Gemeinwohl,Helfen Sie PHP-Lernenden, sich schnell weiterzuentwickeln!