Skip to content

Instantly share code, notes, and snippets.

@mrroot5
Created September 11, 2019 15:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrroot5/8066b2df5d08e582b5aa0d8dcd2be2f2 to your computer and use it in GitHub Desktop.
Save mrroot5/8066b2df5d08e582b5aa0d8dcd2be2f2 to your computer and use it in GitHub Desktop.
Vue DOMContentLoaded: usar vue como si fuera el DOMContentLoaded de JavaScript
<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