![ui/ux resource arsenal | Lava Lamp Lab ui/ux resource arsenal](https://lavalamplab.b-cdn.net/wp-content/uploads/ui-ux-resource-arsenal.jpg)
A Web Developer’s UI/UX Resource Arsenal
May 9, 2022![ui and ux | Lava Lamp Lab ui and ux](https://lavalamplab.b-cdn.net/wp-content/uploads/ui-and-ux.jpg)
UI/UX: Just Because Its A Big Company Doesn’t Make It Right
May 20, 2022![what's new in vue | Lava Lamp Lab what's new in vue](https://lavalamplab.b-cdn.net/wp-content/uploads/vue.jpg)
Introduction
In this blog I will be looking into features that have been added or changed when Vue2 updated to Vue3.
Smaller and faster
Vue3 utilizes an optimization feature known as tree shaking. This means that Vue features that are unused by the project are removed when the project is compiled. This makes projects smaller and therefore faster. Another feature that Vue3 implements is a compiler-informed DOM. This results in Vue3 projects being 41% lighter, 55% faster, having 133% faster updates and using 54% less memory than projects written in Vue2. Check out the link below for the full Vue2 vs Vue3 comparison.
Changes in initialization
- In Vue3, a dedicated “createApp()” function is used to create an app instead of using the “new Vue” instance
new Vue()
– becomes –
createApp()
Vue2 example
![One_Vue2 | Lava Lamp Lab vue 2](https://lavalamplab.b-cdn.net/wp-content/uploads/One_Vue2.png)
Vue3 example
![One_Vue3 | Lava Lamp Lab vue 3](https://lavalamplab.b-cdn.net/wp-content/uploads/One_Vue3.png)
data: { msg: 'It works!' }
– becomes –
data() { return { msg: 'It works!' }; }
Vue2 example
![Two_Vue2 | Lava Lamp Lab Vue 2](https://lavalamplab.b-cdn.net/wp-content/uploads/Two_Vue2.png)
Vue3 example
![Two_Vue3 | Lava Lamp Lab Vue 3](https://lavalamplab.b-cdn.net/wp-content/uploads/Two_Vue3.png)
- Although using “data” as a method was recommended in Vue2, writing “data” as an object was also allowed. This has been changed in Vue3, with it being mandatory to have “data” as a method.
- “Vue.component()” or other examples like “Vue.use()” in Vue2 has been changed to “app.component()” etc.
Vue.component()
- becomes -
app.component()
Vue2 example
![Three_Vue2 | Lava Lamp Lab Vue 2](https://lavalamplab.b-cdn.net/wp-content/uploads/Three_Vue2-1024x755.png)
Vue3 example
![Three_Vue3 | Lava Lamp Lab Vue 3](https://lavalamplab.b-cdn.net/wp-content/uploads/Three_Vue3-1024x840.png)
Teleport
Teleport is a component that has been built into Vue3. This feature makes it possible to “teleport” a part of a components template into a DOM node residing outside of that component’s DOM hierarchy.
Vue3 – Teleport example
![Five | Lava Lamp Lab teleport](https://lavalamplab.b-cdn.net/wp-content/uploads/Five.png)
Composition API
Vue2 – Options API example
![Four_Vue2 | Lava Lamp Lab Vue2](https://lavalamplab.b-cdn.net/wp-content/uploads/Four_Vue2.png)
Vue3 – Composition API example
![Four_Vue3 | Lava Lamp Lab Vue3](https://lavalamplab.b-cdn.net/wp-content/uploads/Four_Vue3.png)
The main difference between the two API’s is the syntax in which it is written. The Options API requires you to have a large single exportable object, where the Composition API allows for compartmentalizing of code. This results in smaller and more understandable code, as related code can be grouped together.
This is especially beneficial when working with bigger projects where code can become large and confusing.
Vue2 – Options API Grouping example
![Six_Vue2 | Lava Lamp Lab Vue2](https://lavalamplab.b-cdn.net/wp-content/uploads/Six_Vue2.png)
Vue3 – Composition API Grouping example
![Six_Vue3 | Lava Lamp Lab Vue3](https://lavalamplab.b-cdn.net/wp-content/uploads/Six_Vue3.png)
Other Changes
Other changes to Vue3 include:
- Multiple root elements: Vue3 allows you to have multiple root elements per template, which was not allowed in Vue2.
- Multiple v-models: Vue3 also allows multiple v-models on a single element, where Vue2 did not.
Summary
Although many features remain the same from Vue2 to Vue3, the changes improve maintainability, readability and speed.