Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can Vue2 components be used in Vue3

Tags:

npm

vuejs2

vuejs3

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)?

like image 299
dlkulp Avatar asked Dec 31 '22 21:12

dlkulp


1 Answers

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.

like image 131
Daniel Avatar answered Jan 13 '23 10:01

Daniel