Skip to content

Instantly share code, notes, and snippets.

@tr4g
Created Jun 16, 2020
Embed
What would you like to do?
loader para botones de VueJS
/**
* Muestra un loader en un boton y llama a una funcion con el detenedor como metodo
*
* by @sebolio
*/
/**
* Modo de uso:
*
* [Importación en componente Vue]
* import btnLoader from '../../btnLoader'
*
* [Iniciación]
* async mounted () {
* ...
* this.btnLoader = btnLoader(this)
* }
*
* [Código del Botón]
* <vs-button @click="btnLoader($event, tuFuncion)">Crear cuenta</vs-button>
*
* [Implementación en tu función]
* tuFuncion(stopLoader) {
* ...tu código...
* stopLoader()
* }
*
*
*/
/**
* btnLoader
*
* event - $event
* action - funcion que se quiere ejecutar
* bgColor - #000, primary, etc
* txtColor - #fff, warning, etc
*/
export default component => function btnLoader (event, action, bgColor, txtColor) {
const element = event.target
component.$vs.loading({
background: bgColor || 'primary',
color: txtColor || '#fff',
container: element,
scale: 0.45
})
setTimeout(_ => action(() => this.$vs.loading.close(element)), 300)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment