In my apiData: []
there’s a time object that updates on the backend every second. The only way I can see the time change is when I refresh the page. However, I don’t want the page to refresh but rather set the fetch API on a setInterval so I can see the time change every second. So I did that but all it does is adds to my data instead of replacing it with refreshed data. I hope this makes sense. How do I fix this?
Also, I realize this is incomplete as I don’t need to share all of my other code since I am working for a compnay, I don’t want to share other important information.
data: function() {
return {
message: 'We are live',
date: new Date().getTime(),
time: '',
apiData: [],
created(){
this.fetchAPI()
}
fetchAPI(){
setInterval(() => {
fetch(`url`)
.then((response) => response.json())
.then(results => {
console.log('Success', results);
if(results.success){
this.apiData = this.apiData = results.data.stats;
this.sortData();
}else{
console.log('Error', results);
}
}).catch((error) => {
console.log('Error', error);
});
}) }
``