Created
June 6, 2019 15:23
-
-
Save victorwpbastos/5f4e0c6cd1d40c3d5d85dbccecc8f3be to your computer and use it in GitHub Desktop.
Vue loading handler component
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
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