Refer to Vue.js lifecycle hooks
- created: At this stage, the instance has finished processing the options which means the following have been set up: data observation, computed properties, methods, watch/event callbacks. However, the mounting phase has not been started, and the $el property will not be available yet.
- mounted: Called after the instance has been mounted, where el is replaced by the newly created vm.$el. If the root instance is mounted to an in-document element, vm.$el will also be in-document when mounted is called.
There is beforeCreate
and beforeMount
as well.
Sample code of listening to mounted
in Vue.js Component.
<template>
...
</template>
<script>
export default {
...
mounted: function () {
// do something after element is mounted
}
}
</script>
<style scoped>
</style>
You can listen to the events on Vue.js Instance as well.
new Vue({ data: { ... }, created: function () { }})