Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
24
rated 0 times [  29] [ 5]  / answers: 1 / hits: 110104  / 8 Years ago, tue, april 12, 2016, 12:00:00

(New to Vue.js) I fetch data from a get request to display calendar information. I want this to update every 5 minutes.



Nothing in the docs about auto reload - how would I go about implementing this? Do I use standard javascript within the file or something else?



My complete app.js below:



Vue.component('events', {
template: '#events-template',

data: function() {
return {
list: []
}
},

created: function() {

this.fetchEventsList();
},

methods: {

fetchEventsList: function() {

this.$http.get('events', function(events) {

this.list = events;

}).bind(this);

}

}

});

new Vue({
el: 'body',


});

More From » reload

 Answers
2

No need to re-invent the wheel, window.setInterval() does the job pretty well


Vue.component('events', {
template: '#events-template',

data () {
return {
list: [],
timer: ''
}
},
created () {
this.fetchEventsList();
this.timer = setInterval(this.fetchEventsList, 300000);
},
methods: {
fetchEventsList () {
this.$http.get('events', (events) => {
this.list = events;
}).bind(this);
},
cancelAutoUpdate () {
clearInterval(this.timer);
}
},
beforeUnmount () {
this.cancelAutoUpdate();
}
});

new Vue({
el: 'body',
});

[#62596] Monday, April 11, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
madelyn

Total Points: 449
Total Questions: 100
Total Answers: 100

Location: Seychelles
Member since Fri, May 7, 2021
3 Years ago
madelyn questions
Wed, Jul 28, 21, 00:00, 3 Years ago
Wed, Jul 14, 21, 00:00, 3 Years ago
Sat, Nov 7, 20, 00:00, 4 Years ago
Thu, Sep 3, 20, 00:00, 4 Years ago
;