![]() |
VOOZH | about |
The long-awaited Vue 3 was officially released on 18 September 2020.
๐ New Features in Vue 3 and How to Use ThemThere is updated documentation for this new version, which Vue published alongside its migration guide. Both are highly readable, well-structured resources to help you get started using Vue 3.
Working with Vue 3 is as easy as using the previous version. If you discover any bugs or issues along the way, you can report them using Vue Issue Helper.
In this guide, weโll walk you through the current state of the Vue framework and give you some tips and foundational knowledge to help you start using Vue 3.
Weโll cover the following:
Letโs get started!
The Replay is a weekly newsletter for dev and engineering leaders.
Delivered once a week, it's your curated guide to the most important conversations around frontend dev, emerging AI tools, and the state of modern software.
Among the highlights of Vue 3 is its performance. Overall, Vue 3 is about 55 percent faster, updates are up to 133 percent faster, and memory usage is down to 54 percent. This is achieved by completely rewriting the DOM implementation using TypeScript.
Other performance improvements include:
Tree-shaking is the process of eliminating dead, useless, or unused code, thereby decreasing the build size of an app.
With the new changes, Vue 3โs build size is 13.5kb. It slims down nicely to 11.75kb when you strip away everything but the Composition API support.
Even with all the bells and whistles, Vue 3 is only 22.5kb, which is still lighter than Vue 2 with all features included due to tree-shaking.
This is one of the biggest changes to Vue. It is entirely additive and introduces breaking changes to the previous Options API. While the Composition API advances, the Options API will continue to be supported.
// src/components/UserRepositories.vue
export default {
components: { RepositoriesFilters, RepositoriesSortBy, RepositoriesList },
props: {
user: { type: String }
},
setup(props) {
console.log(props) // { user: '' }
return {} // anything returned here will be available for the rest of the component
}
// the "rest" of the component
}
TeleportTeleport is a new Vue 3 feature that allows you to decide where to render a piece of HTML with many DOM parents. You can now render HTML in different places in the DOM without creating a global state or different components.
app.component('modal-button', {
template: `
<button @click="modalOpen = true">
Open full screen modal! (With teleport!)
</button>
<teleport to="body">
<div v-if="modalOpen" class="modal">
<div>
I'm a teleported modal!
(My parent is "body")
<button @click="modalOpen = false">
Close
</button>
</div>
</div>
</teleport>
`,
data() {
return {
modalOpen: false
}
}
})
When the button is clicked, Vue renders the content of the modal inside the body tag as a child of the body tag.
Vue 3 now supports mulitroot node components called fragments. This was not supported in older versions of Vue.
<!-- Layout.vue --> <template> <header>...</header> <main v-bind="$attrs">...</main> <footer>...</footer> </template>
Vue 3โs codebase is written in TypeScript. This enables it to automatically generate, test, and bundle up-to-date type definitions.
Vue now supports JSX and class components are still supported with TypeScript. In other words, you can create a Vue app with either TypeScript or JavaScript, depending on your expertise.
interface Book {
title: string
author: string
year: number
}
const Component = defineComponent({
data() {
return {
book: {
title: 'Vue 3 Guide',
author: 'Vue Team',
year: 2020
} as Book
}
}
})
Vue 3 introduces too many breaking changes to adequately cover in one article. For more on the following, head to the official docs.
function attribute on single-file component (SFC) is deprecatedmodel component option and v-bindโs sync modifier are removed in favor of v-model argumentsdefineAsyncComponent method is required to create async components$scopedSlots property is replaced with $slotsVue 3 comes with many great features and enhancement to the Options API and also introduces some experimental features. You can use these features in your development phase and send feedback to the Vue core team.
Suspense is an essential feature even though itโs still in the experimental phase. It serves as a component that renders fallback contents when a condition is met and is used to conditionally render contents.
suspense comes in handy when you want to make an API call back to display the content when fully loaded or show a loading message while itโs processing.
<Suspense> <template > <Suspended-component /> </template> <template #fallback> Loading... </template> </Suspense>
The above is a simple example of how you can use suspense and fallback to handle API requests.
<script setup>When using the <script> tag in Vue 3 to create a single-page component with the new Composition API, youโd put all your methods and variables inside the setup() method. But with the new <script setup>, you can simply create your component without using the setup() method or returning anything.
The old way:
<script>
import { ref } from 'vue'
export default {
setup() {
const variable = ref(0)
const inc = () => variable.value++
return {
variable,
inc,
}
},
}
</script>
The new way:
<script setup>
import { ref } from 'vue'
export const count = ref(0)
export const inc = () => count.value++
</script>
Without using the setup method, everything still works and the code is more concise.
<setup vars>This is also a very useful feature introduced in Vue 3, it allows developers to reference component state inside our style declaration. A very basic example will be declaring a reactive property and accessing it inside the <style> tag.
<template>
<div class="text-color">This is my text </div>
<template>
<script>
export default {
data() {
return {
color: 'green'
}
}
}
</script>
<style vars="{ color }">
.text-color {
color: var(--color);
}
</style>
By using the vars and var properties, you can declare a CSS property with a reactive value.
If you have a project written in Vue 2, you might be wondering how migrations will be handled. The Vue team will release one last update for Vue 2 that is backward-compatible with Vue 3. The team will also add depreciation warnings for changes that will cause your app to break. This long-term support (LTS) version will last for 18 months, which means it will still get security updates and is absolutely safe to keep using.
The migration guide, which is still in beta, will include a compatibility build for Vue 3 and also a command-line migration tool, which will help with automatic migration and provide hints where necessary.
npm init vite-app hello-vue3
const HelloVueApp = {
data() {
return {
message: 'Hello Vue!!'
}
}
}
Vue.createApp(HelloVueApp).mount('#hello-vue')
//--------------------------------------------------
<div id="hello-vue" class="demo">
{{ message }}
</div>
In this tutorial, we explored the new features and breaking changes introduced with Vue 3. We also demonstrated how to start a new Vue 3 project using the vite library and how to migrate your old Vue 2 project to Vue 3.
Debugging Vue.js applications can be difficult, especially when users experience issues that are difficult to reproduce. If youโre interested in monitoring and tracking Vue mutations and actions for all of your users in production, try LogRocket.
๐ LogRocket Dashboard Free Trial BannerLogRocket lets you replay user sessions, eliminating guesswork by showing exactly what users experienced. It captures console logs, errors, network requests, and pixel-perfect DOM recordings โ compatible with all frameworks.
With Galileo AI, you can instantly identify and explain user struggles with automated monitoring of your entire product experience.
Modernize how you debug your Vue apps โ start monitoring for free.
Learn how to use Gemini CLI subagents to delegate frontend, backend, testing, and docs tasks to specialized agents with guardrails and clear ownership.
Learn how next-browser gives AI agents runtime context for debugging Next.js apps, including React props, hydration, PPR, forms, and performance.
Build dynamic LLM routing in Next.js with OpenRouter, TanStack AI, task classification, model fallbacks, and cost-aware routing.
TSRX adds first-class control flow, conditional hooks, and scoped styles to React via a TypeScript compiler extension โ no new framework required.
Hey there, want to help make our blog better?
Join LogRocketโs Content Advisory Board. Youโll help inform the type of content we create and get access to exclusive meetups, social accreditation, and swag.
Sign up now