Skip to content
Advertisement

How to execute a function when all components are mounted

I’m using VueJS with the Vue Router and a js uniform module to modify form elements like select, checkboxes, etc to wrap these elements in a new element to improve the way we can style them.

How can I efficiently execute this module after I changed route and my components are mounted?

I could manually initialize the module in the mounted function for every component/view but that would be crazy. Adding a route watcher on the VUE instance kind of works but this is being triggered before my components are mounted so the HTML I need to modify is not there yet.

What is the best practice solution for this problem in VueJS?

Advertisement

Answer

Perhaps a global mixin would work. Here’s the documentation: https://v2.vuejs.org/v2/guide/mixins.html#Global-Mixin

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement