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

143
Views
How to trigger an API every 3 seconds in the vue framework?

I am a vue beginner and would like to ask a question! My English is not good but I try to describe my problem completely, thank you.

Currently I use vue to learn how to access the API, but I hope to be able to automatically touch the API again every 3 seconds to update the screen, but I really don’t know how to achieve this?

Hope to get your help, thank you again for watching my question.

My example

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Add setInterval in created hook that calls the method that loads the data :

Vue.createApp({
    data() {
    return {
      status: true,
      data: [],
      interval:null
    };
  },
  methods: {
    reNew() {
      axios.get("https://randomuser.me/api/?results=5").then(
      (response) =>
          // console.log(response)
          (this.data = response.data.results)
      )
    }
  },
  mounted() {
    this.reNew()
  },
  created(){
    this.interval = setInterval(() =>{
      this.reNew()},3000)
  },
  destroyed(){
    clearInterval(this.interval)
  }
}).mount('#app');
about 4 years ago · Juan Pablo Isaza Report

0

You can use the setInterval method.

This would execute the function every 3 seconds.

setInterval(function(){ 
// fetch data...
}, 3000);
about 4 years ago · Juan Pablo Isaza Report
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!