Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

155
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!