data() {
return { status: null, pollInterval: null }
},
...
methods() { fetchData() { axios.get('r/http://api/process/status') .then((response) => { //check if status is completed, if it is stop polling if(response.data.status = 'completed') { clearInterval(this.pollInterval) //won't be polled anymore } this.status = response; }); } },
mounted() { this.fetchData() //check if the status is completed, if not fetch data every 10minutes if(this.status.status != 'completed') { this.pollInterval = setInterval(this.fetchData(), 600000) //save reference to the interval setTimeout(() => {clearInterval(this.pollInterval}, 36000000) //stop polling after an hour } }