Skip to content

Instantly share code, notes, and snippets.

@victorwpbastos
Created June 6, 2019 15:23
Show Gist options
  • Save victorwpbastos/5f4e0c6cd1d40c3d5d85dbccecc8f3be to your computer and use it in GitHub Desktop.
Save victorwpbastos/5f4e0c6cd1d40c3d5d85dbccecc8f3be to your computer and use it in GitHub Desktop.
Vue loading handler component
import Vue from 'vue';
import { VDialog, VCard, VCardText, VProgressLinear } from 'vuetify/lib';
export default async function useLoadingHandler(fn = () => {}, message = 'Processando requisição...') {
let loadingView = new Vue({
components: { VDialog, VCard, VCardText, VProgressLinear },
data() {
return {
show: false
};
},
render: function(h) {
return h(
'v-dialog',
{
props: {
value: this.show,
persistent: true,
width: '300'
}
},
[
h('v-card', [
h('v-card-text', [
h('div', message),
h('v-progress-linear', {
props: {
indeterminate: true,
color: 'primary'
},
class: ['mb-0']
})
])
])
]
);
},
mounted() {
document.body.appendChild(this.$el);
setTimeout(() => {
this.show = true;
}, 500);
},
beforeDestroy() {
this.show = false;
document.body.removeChild(this.$el);
}
});
try {
loadingView.$mount();
await fn();
} finally {
loadingView.$destroy();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment