Skip to content

Instantly share code, notes, and snippets.

@voltuer
Created June 16, 2020 14:09
Show Gist options
  • Save voltuer/95556c88ac1a341120e9848226e7ef36 to your computer and use it in GitHub Desktop.
Save voltuer/95556c88ac1a341120e9848226e7ef36 to your computer and use it in GitHub Desktop.
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