Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Vue 3 Introduction

Vue 3 Introduction

Vue 3 is a progressive framework for building user interfaces.

Progressive means you can introduce only a part of Vue's capabilities as your project needs: from a simple page interaction enhancement, to building a complete single-page application (SPA), and even server-side rendering (SSR) applications—Vue 3 can handle them all.

Vue 3 is a progressive JavaScript front-end framework led by Evan You, officially released on September 18, 2020, codenamed One Piece.

Compared with Vue 2, Vue 3 underwent a comprehensive rewrite of its core architecture: the reactivity system changed from Object.defineProperty to Proxy, introduced the Composition API, and achieved overall improvements in performance, TypeScript support, and bundle size.

Vue 3's official positioning is:a framework that is easy to get started with while being capable enough to support complex projects. It neither enforces a specific architecture like Angular, nor requires a lot of manual optimization like React; instead it finds a balance between usability and capability.

The Essential Difference Between Vue 3 and Vue 2

Vue 3 is not a patch upgrade of Vue 2, but a complete rewrite.

Comparison Item Vue2 Vue3
Reactivity Principle Object.defineProperty, unable to detect newly added properties and array index changes Proxy, fully proxies all operations on objects, with none of the above limitations
Code Organization Options API: data, methods, and computed are separated Composition API: code is aggregated by logical concern
TypeScript Support Adapted later, with limited type inference Core code rewritten in TypeScript; TS is a first-class citizen
Bundle Size About 20KB runtime (gzip) Supports Tree-shaking and on-demand bundling; minimum is only 13.5KB
Performance Baseline Initial render about 55% faster, update render about 133% faster, and memory usage reduced by about 54%
Component Template Root Node Must have one and only one root element Supports multiple root nodes (Fragment)
Global API Mounted on the Vue constructor; multiple instances share state Pass createApp Creates independent instances with more thorough isolation

Core Features

Vue 3's improvements cover four dimensions: the reactivity system, API design, the compiler, and new built-in components.

Composition API

The Composition API is the most important design change in Vue 3; it solves the fundamental pain point of the Options API in Vue 2:Related logic is scattered across different options, making reuse difficult.

In the Options API, the data for a "user search" feature may be scattered across data, methods, computed, watch four options; whereas the Composition API lets you write all the logic of the same feature together, then extract it into a reusable function (Composable).

Example: Options API vs Composition API

Example: Recommended approach (script setup syntax sugar)

New Built-in Components

Vue 3 added three built-in components, solving three categories of high-frequency scenarios in front-end development.

Component Problem Solved Typical Use Case
Fragment Vue 2 required a component template to have a single root node; Fragment allows multiple root nodes to coexist (no extra wrapping div needed) List item components, reducing unnecessary DOM nesting
Teleport Renders a component's HTML to any specified position in the DOM, breaking through the parent component's CSS stacking context limitation Global Modal dialogs, Toast notifications, floating toolbars
Suspense Gracefully displays fallback content before an async component finishes loading, unifying the handling of async waiting states Skeleton screens for lazily loaded components, and Loading during route switches

Example: Teleport for global modals

Example: Suspense handling async component loading