Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

156
Vistas
Vue3 + axios: how to cancel specific dynamic AJAX requests?

I have a project with many pages (components) where each page is making multiple long AJAX requests. I need to cancel SOME of them in a specific moment in time (switching between pages).

When I was using Vue2 + vue-resource I was able to put all my xhrRequests into array

Vue.http.get(url + action, {
   params: params, 
   before: function (xhr) {
      Vue.xhrRequests.push(xhr)
  }
}).then((response) => {
  helper.success(response)
}).catch(function (error) {
  helper.failure(error)
})

and anytime I wanted I could iterate over this array and cancel requests I wanted to cancel. Decision about which requests to cancel was made based on request URL.

  for (let i = 0; i < Vue.xhrRequests.length; i++) {
    if (Vue.xhrRequests[i].url.indexOf('news') >= 0 && Vue.xhrRequests[i].url.indexOf('select') < 0) {
      Vue.xhrRequests[i].abort()
    }
  }

Now I am migrating to Vue3 and I need to use axios or Fetch API (or anything else). I know I can use signal or source approaches, but when I have a lot of pages (components) and each page is making different requests it's getting tricky.

UPDATE: I tried to use axios interceptos

axios.interceptors.request.use(function (config) {
   console.log(config)
   return config;
}, function (error) {
   return Promise.reject(error);
});

but I can't see URL in config :/

Any ideas?

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda