What are the key differences between Vue 2 and Vue 3? (Migration Guide)
Vue 3是重大重写,核心变化包括Proxy响应式系统(ref/reactive替代data)、Composition API(setup替代选项式API)、多根节点模板、Teleport/Suspense等新特性,以及移除filters、重构v-model和全局API。

Vue 3 is a major rewrite—not just an upgrade—so core concepts, syntax, and internal behavior changed meaningfully. The shift focuses on better performance, stronger TypeScript support, improved reactivity, and more flexible composition patterns. Below are the key differences you’ll encounter when migrating or learning Vue 3.
Reactivity System: ref() vs. data()
Vue 2 used a hidden, object-based reactivity system that wrapped data properties in getters/setters. Vue 3 replaces this with Proxy-based reactivity, which is more consistent and supports arrays, Maps, Sets, and nested objects out of the box.
- In Vue 2, reactivity was declared inside a
data()function returning an object; changes to new properties requiredthis.$set(). - In Vue 3, reactive state is created explicitly using
ref()(for primitives) andreactive()(for objects). You must use.valueto access or assign values from aref. -
setup()replacesdata,computed,methods, and lifecycle hooks — all defined inside it before the component renders.
Composition API: setup() and logical reuse
The Composition API is optional in Vue 2 (via plugin), but built-in and idiomatic in Vue 3. It lets you group related logic by concern instead of by option type.
-
setup()runs beforecreated()and receivespropsandcontext(containingemit,slots,attrs). - Logic can be extracted into reusable functions (composables) — e.g.,
useMouse(),useFetch()— without mixins or renderless components. - Lifecycle hooks like
onMounted,onUpdated, andonUnmountedare now imported and used insidesetup().
Template & Rendering: Fragments, teleport, and dynamic components
Vue 3 removes several template limitations and introduces new built-in features:
- Fragments: Templates can have multiple root nodes — no need for a wrapping
<div>. -
<Teleport>: Built-in component for rendering content elsewhere in the DOM (e.g., modals, tooltips). -
<Suspense>: Built-in async boundary for waiting on async setup() or async components. -
<KeepAlive>and<Transition>are now components (not directives), and their usage is more consistent.
Breaking Changes & Compatibility Notes
Some Vue 2 patterns no longer work without adjustment:
-
filterswere removed — use computed properties or plain functions instead. -
v-modelnow compiles tomodelValueprop +update:modelValueevent by default (customizable viamodeloption in defineComponent). -
vm.$children,vm.$listeners, andvm.$scopedSlotsare gone — useslots,emit, and explicit props. - Global API is tree-shakable:
Vue.use(),Vue.mixin(),Vue.component()are replaced by app instance methods likeapp.use(),app.mixin(),app.component().
The above is the detailed content of What are the key differences between Vue 2 and Vue 3? (Migration Guide). For more information, please follow other related articles on the PHP Chinese website!
Hot AI Tools
Undress AI Tool
Undress images for free
AI Clothes Remover
Online AI tool for removing clothes from photos.
Undresser.AI Undress
AI-powered app for creating realistic nude photos
ArtGPT
AI image generator for creative art from text prompts.
Stock Market GPT
AI powered investment research for smarter decisions
Hot Article
Popular tool
Notepad++7.3.1
Easy-to-use and free code editor
SublimeText3 Chinese version
Chinese version, very easy to use
Zend Studio 13.0.1
Powerful PHP integrated development environment
Dreamweaver CS6
Visual web development tools
SublimeText3 Mac version
God-level code editing software (SublimeText3)
Hot Topics
20528
7
13637
4
A quick way to handle form validation in Vue.js using Vuelidate.
Mar 13, 2026 am 01:15 AM
VuelidatevalidatesJavaScriptobjects—notHTMLformelements—usingdeclarativerules;usersmustmanuallywireUIeventslike@blurandcall$touch()or$validate(),avoiding$autoDirtyforbetterUX.
A quick guide to configuring ESLint and Prettier for a Vue.js project.
Mar 12, 2026 am 01:03 AM
ESLintandPrettierconflictinVueprojectsbecauseESLint’svue/script-indentruleclasheswithPrettier’sindentationlogicinandblocks,causinginconsistentautofixes;thefixisdelegation—Prettierhandlesformatting,ESLinthandlescodequality—bydisablingoverlappingESLint
How to use global properties in Vue.js? (App.config.globalProperties)
Mar 11, 2026 am 12:16 AM
app.config.globalProperties only takes effect for OptionsAPI components and is not available in CompositionAPI; it needs to be configured after createApp() and before mount(), and the mounting function must pay attention to this binding; it is recommended to use provide/inject, combined functions or Pinia instead.
How to integrate a third-party JavaScript library into a Vue.js project?
Mar 14, 2026 am 01:15 AM
Vue projects should install third-party libraries through npm/yarn, giving priority to importing them using ES modules and introducing them on demand. Pay attention to DOM dependencies, SSR compatibility, TypeScript type declarations and build configuration adaptation.
How to improve SEO for a client-side rendered Vue.js application?
Mar 14, 2026 am 01:14 AM
No—Vue.jsSSRdoesn’tsolveSEOoutofthebox;plainVueCLIorViteappsrenderonlyinthebrowser,riskingemptyHTMLforcrawlers.Prerenderingstaticpagesatbuildtimeistheminimalfixformostlystaticsites,butrequiresknownroutesandbaked-indata.Fordynamiccontent,SSGorSSRisnee
How to create a server route (API endpoint) in a Nuxt 3 and Vue.js project?
Mar 12, 2026 am 12:57 AM
Nuxt3 automatically registers files in the server/api/ directory as API endpoints without additional configuration; file paths are directly mapped to HTTP routes, supporting static, nested, dynamic parameters (such as [id].ts) and REST-style naming (such as items.post.ts). You need to use defineEventHandler to encapsulate the processing function, and obtain parameters and request bodies through getQuery and readBody. Please note that environment variables must be accessed using useRuntimeConfig().
How to use Vite plugins with Vue.js? (Auto-import components guide)
Mar 12, 2026 am 01:26 AM
vite-plugin-components (now unplugin-vue-components) is more reliable because the static analysis template automatically injects imports during construction, avoiding manual omissions and path maintenance problems, and does not invade the script logic layer.
How to integrate Swiper.js for carousels in Vue.js? (Responsive slider)
Mar 13, 2026 am 12:18 AM
Vue3 Swiper11 must use the useSwiper hook to obtain the responsive instance. The configuration must be wrapped with computed and strictly nested swiper→swiper-wrapper→swiper-slide. Under SSR, ClientOnly or window must be used to determine to avoid errors.





