Migration Plan To The All New Vue JS 3
Vue 3 is here and everyone is looking forward to catching up with the upgrade ASAP.
Vue JS is the best client-side framework out there! It has improved its bundle size and performance under the hood, making this new version appealing to the developers.
What’s the catch? Some breaking changes, deprecations, and new syntax might make your migration plan slightly harder than expected. Let’s dive in and see what you should expect.
In this article, we’ll look at how you can upgrade your Vue.js 2 application into Vue 3, and what are the breaking changes you should expect in Vue 3.
How to upgrade from Vue 2 to Vue 3
Let’s assume a scenario where you have a usual Vue.js project. You would also have a main.js file where you import the Vue router and Vuex configuration and set it to the Vue instance.
Using the CLI
Now to upgrade a Vue.js 2 project to Vue.js 3 project, you can simply add an official CLI for Vue projects, the Vue-next plugin. Besides deployment and development tooling, it simplifies the upgrade to a one-line command:
This plugin upgrades and installs the new dependencies for Vue Router, Vue, and Vuex. It also modifies the code to be compatible with Vue 3 version.
So it becomes important to create a backup of your project at the very start.
Installing the plugin upgrades the packages @vue/test-utils, eslint-plugin-vue, vue-router, vuex, and vue to the new version. Also, a new package appears among the development dependencies, named @vue/compiler-sfc.
The first thing you will notice is that the way of instantiating and configuring your application has changed. It looks and works much better than before.
Same for the Vue router. If you take a look at the configuration file, a new VueRouter becomes a call to createRouter, and the global plugin setup must be left. Instead, you’ll be using some functions from this library.
The same goes for the Vuex Store. You can use the new ‘createStore’ function to create a new instance and set the store configuration.
Breaking Changes You Would See in Vue 3
The above modifications are done automatically by the Vue CLI.
All you have to do now is to start experimenting with all the below new features that Vue 3 offers for which you will need experienced developers. Let’s understand this better.
Vue Filters and Eventbus are deprecated in the new version. EventBus was there in the Vue development whenever you’re facing a situation where you need to make a shortcut to emit events from a child to parent, or vice versa. Whereas, filters were there to help you ‘format’ your value, for example: to short URL, add currency, uppercase, etc.
You will need experts in complex cases to make the required changes in your application code and refactor both of them.
You should expect a more maintainable, smaller, faster version with the new features. Most of them are additions and improvements over the existing API.
Composition API is Vue 3’s biggest feature so far, which provides an alternate syntax for using TypeScript, reusing code across components, and writing larger components.
This is an alternative syntax and not the new way we code components in Vue 3. You might choose to use it based on the above three reasons.
Another good thing is that the existing Options API is not deprecated. Everything is for handling advanced use cases and mainly replace mixins usage that admittedly has caused a lot of problems in large scale applications.
As we mentioned before, the first thing that you will notice is the difference in initializing your app. In Vue 2 you use Vue constructor with the $mount method and a render function like this:
In Vue 3, you will find a more elegant syntax
In Vue 2, multi-root components were not supported. The solution was to wrap your code in a wrapper element.
In Vue 3, components can have multiple root nodes now. This removes the use of wrapper elements and enables writing a cleaner markup.
Having part of your component mounted in a different position in DOM than the Vue component hierarchy has been seen as a difficult situation to solve.
The teleport feature helps in creating a component that includes a full-screen modal. In most cases, you’d want the modal’s logic to live within the component, but either it starts requiring a change in component composition or the positioning of the modal quickly becomes hard to solve through CSS.
You can still interact and pass props to it like being inside the component!
If you want your Vue.js application to become faster, smaller, more maintainable, you should upgrade to Vue 3 with an easier approach to target native.
If you want to wait for Vue.js Migration Build release for the whole upgrade process, you can still stick to using Vue.js 2, as it’s stable and it works with any third-party library or tool.
If planning for migration, we recommend that you hire experts who can assist you with a proper migration plan and ensuing and development process, especially as the supporting libraries are still getting updated.
Contact us for your new custom or single-page application Vue.JS project.
About Galaxy Weblinks
We specialize in delivering end-to-end Vue.js software development services, apart from other popular JS frameworks. Our team of skilled and dedicated Vue.JS developers provides initial consultation, migration plan, and the final Vue.JS web app development & support. We deliver powerful front-ends, real-time applications, and single-page apps (SPAs) with on-time delivery with an agile & devOps approach.
About Galaxy WeblinksWe specialize in human-centric user experience design services to our clients across the globe. Our innovative ideas, creative designs, industry best practices, and processes help us improve user satisfaction and solve complex design problems. Contact us for a free consultation!
The first part of this series uncovered the idea of Micro Frontends that is to break down the frontend monolith into...
Craft is a mature and tested content management system. Airbnb, W3C, Netflix, PBS, Salesforce, Moz, and countles...
Developers use Text Editors, also known as code editors, for editing programming code. These editors basically contai...
Your business is growing and your team is doing their best to meet the tight deadlines and increased workload. You ma...
Even though there is no word on Angular 10’s release and to be honest it’s too early to expect a release, the develop...
Kotlin has emerged as both substitute and supplement to C++ and Java. In 2018, the language had over 96,000 repositor...
Angular 6, released earlier in May 2018 didn’t offer much improvements on the performance part. It was mainly focused...
Google recently announced Mobile-First Indexing after a year and half of extensive experimenting and testing. The sea...