Add FetchData component

This commit is contained in:
James Brooks 2018-06-17 11:47:53 +01:00
parent d678e7d594
commit 98cd8383a1
2 changed files with 34 additions and 1 deletions

View File

@ -27,6 +27,8 @@ window.axios.defaults.headers.common = {
* or customize the JavaScript scaffolding to fit your unique needs.
*/
Vue.component('fetch-data', require('./components/FetchData'));
new Vue({
el: '#app',
data () {
@ -48,5 +50,5 @@ window.axios.defaults.headers.common = {
'invite-team': require('./components/dashboard/InviteTeam'),
'metric-chart': require('./components/status-page/Metric'),
}
})
});
})()

View File

@ -0,0 +1,31 @@
<script>
export default {
props: ['url'],
data() {
return {
loaded: false,
response: null,
}
},
created() {
axios.get(this.url)
.then((response) => {
this.response = response
this.loaded = true
})
},
render() {
if (!this.loaded) {
return this.$scopedSlots.default({
loading: true,
response: null,
})
}
return this.$scopedSlots.default({
loading: false,
response: this.response.data,
})
},
}
</script>