[Vuejs]-Repetedly call a axios.get to display data from endpoint

3๐Ÿ‘

โœ…

You can do something in the mounted hook:

mounted(){
    this.interval = setInterval(() => {
        axios.get(this.my_url).then(res => { /* do something */});
    }, 30000 );
},
data(){
    return {
        interval: undefined,
         my_url: undefined
    }
}

setInterval is a javascript function that allow you to run a function every predefined milliseconds. You can cancel it later with the following command: clearInterval(this.interval). You can also change my_url when you want ๐Ÿ™‚

Leave a comment