Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Changes in Vue life cycle for Vue2

I am migrating Vue2 to Vue3. For this, I want to start the changes that Vue2 can handle. So here are the changes in Vue3 lifecycle:

enter image description here

So I want to apply these changes and add setup, before I move to vue3. I see that Vue2 already handle with these changes because when I see the components, I dont get any error but I still wanted to ask if I already add setup() and add onMounted inside of it instead of mounted, will it work for vue2?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

As an example:

setup() {
   onMounted(() => {
     ...
})
}

will the example work for Vue2?

>Solution :

The function like you see have not the same name, this will not throw a error because you just define a function.

But in vue2 if you rewrite your mounted by onMounted, the function is not understand and doesn’t exist in the lifecycle. It will be never called.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading