Sometimes, we want to trigger event after component has been rendered in Vue.js.
In this article, we’ll look at how to trigger event after component has been rendered in Vue.js.
How to trigger event after component has been rendered in Vue.js?
To trigger event after component has been rendered in Vue.js, we can call this.$emit
in the mounted
hook.
For instance, we write
<script>
export default {
//...
mounted() {
this.$emit("loaded");
},
//...
};
</script>
to emit the loaded
event in the mounted
hook with this.$emit
.
Conclusion
To trigger event after component has been rendered in Vue.js, we can call this.$emit
in the mounted
hook.