0

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?

As an example:

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

will the example work for Vue2?

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Can I ask additional question about upgrade then? Which changes can I apply in Vue2 before I completely move to Vue3?
Every project i work started with vue2 is still with it so i'm not really able to respond. But i think some change will throw a error like the way the app is mounted inside main.js. You can fund some fondamental change ir bacancytechnology.com/blog/migrate-from-vue-2-to-vue-3, the way is simple just try a migration on vue3 and see what problem you have.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.