[Vuejs]-How to instant data refresh with Laravel and vue.js?

1👍

Change your setInterval function to arrow function like this.

setInterval(() => {
       axios
            .get("/get-total-meetings")
            .then(response => (this.totalMeetings = response.data))
            .catch(error => {
            this.errors.push(error);
        });
}, 2000);

You could put a watcher for that to be able vue to watch the changes of your data. like this.

watch: {
  totalMeetings(val) {
       this.totalMeetings = val
  }
}

Or create a computed property for it to update the value when it changes.

computed: {
    total_meetings() {
       return this.totalMeetings
    }
}

then your component should look like this

<p class="tv-value" v-html="total_meetings"></p>

Leave a comment