7

I've currently got a library of Vue2 components I've created and use in several projects via a private npm repo. I'm starting a new project now in Vue3 but I'd like to use the old components if possible. Can I mix versions like that? Also, can components be mixed the opposite way (Vue3 components in Vue2 apps)?

1 Answer 1

10

Vue2 components can be used with Vue3 and Vue3 components can be used in Vue2.

HOWEVER...

As long as you use Classic Vue Js class-based API you should have no issues. Even though some of the underlying technology has been rebuilt, the Vue team has worked hard on making that compatible, though I'm sure there will be some edge cases here and there.

The problem will be if you use the Composition API in making your components. The composition API is built for Vue3, and although you can have a similar experience in Vue2 via a plugin, you are likely going to encounter issues.

Furthermore, even if you are not using the Composition API, you may end up using plugins that do rely on it, which may end up not regression testing against Vue2.

Vue3 is still in RC

At the time of writing, Vue 3 was still being released as a RC version. This may change very soon, there's not guarantee.

If you're going to use Vue3 the same way as Vue2, there's little benefit to switching. If you are going to use the new features (like the Composition API) then you might end up not being 100% compatible.

list of breaking changes

https://v3-migration.vuejs.org/breaking-changes/introduction.html#breaking

By the sounds of it, Vue2 will have another (LTS) release that will address compatibility issues.

The official recommendation is to start new projects with Vue2 still.

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

3 Comments

So if I'm understanding this correctly, Composition API is only a problem if used in Vue3 components loaded into a Vue2 project - even with the plugin?
in short, it depends. For the most part, you'll likely be fine to use vue2 with composition api plugin on a vue3 component, but until the compatibility version of Vue2 is released, you could be finding things don't work entirely the same, or need additional "finessing". One issue that comes to mind is this stackoverflow.com/questions/61885716/…
Upvoted this answer for stating that it's recommended to start with new projects with a stable release instead of blindly using always the latest release, even if it's RC

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.