Created
September 11, 2019 15:23
-
-
Save mrroot5/8066b2df5d08e582b5aa0d8dcd2be2f2 to your computer and use it in GitHub Desktop.
Vue DOMContentLoaded: usar vue como si fuera el DOMContentLoaded de JavaScript
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
<template> | |
<div>{{ asyncText }}</div> | |
</template> | |
<script> | |
export default { | |
data: () => ({ | |
asyncText: 'Mi componente' | |
}), | |
// Usamos el mounted como punto de inicio | |
mounted() { | |
// Docu oficial v2: https://vuejs.org/v2/api/#Vue-nextTick | |
/* | |
* nextTick espera a la siguiente actualizacion del DOM | |
* esta actaulziacion suele darse porque alun dato asincrono | |
* como una variable del store se ha actualizado | |
*/ | |
this.$nextTick().then(() => { | |
this.main() | |
}) | |
}, | |
methods: { | |
main() { | |
this.asyncText = 'Hola! soy tu componente' | |
} | |
} | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment