Last active
April 27, 2019 13:55
-
-
Save themonster2015/2be04ce0f13e9bb5477c9998444d4a03 to your computer and use it in GitHub Desktop.
vue code for periodically polling an api
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
new Vue({ | |
el: '#app', | |
data: { | |
items: [], | |
interval: null, | |
}, | |
methods: { | |
loadData: function () { | |
$.get('/api/data', function (response) { | |
this.items = response.items; | |
}.bind(this)); | |
} | |
}, | |
ready: function () { | |
this.loadData(); | |
this.interval = setInterval(function () { | |
this.loadData(); | |
}.bind(this), 30000); | |
}, | |
beforeDestroy: function(){ | |
clearInterval(this.interval); | |
} | |
}); | |
<div id="app"> | |
<div v-for="item in items">{{ item.prop }}</div> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment