search
  • Sign In
  • Sign Up
Password reset successful

Follow the proiects vou are interested in andi aet the latestnews about them taster

Table of Contents
ref() vs. data() ">Reactivity System: ref() vs. data()
setup() and logical reuse ">Composition API: setup() and logical reuse
Fragments, teleport, and dynamic components ">Template & Rendering: Fragments, teleport, and dynamic components
Breaking Changes & Compatibility Notes
Home Web Front-end Vue.js What are the key differences between Vue 2 and Vue 3? (Migration Guide)

What are the key differences between Vue 2 and Vue 3? (Migration Guide)

Dec 22, 2025 am 02:14 AM

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

What are the key differences between Vue 2 and Vue 3? (Migration Guide)

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 required this.$set().
  • In Vue 3, reactive state is created explicitly using ref() (for primitives) and reactive() (for objects). You must use .value to access or assign values from a ref.
  • setup() replaces data, 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 before created() and receives props and context (containing emit, slots, attrs).
  • Logic can be extracted into reusable functions (composables) — e.g., useMouse(), useFetch() — without mixins or renderless components.
  • Lifecycle hooks like onMounted, onUpdated, and onUnmounted are now imported and used inside setup().

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:

  • filters were removed — use computed properties or plain functions instead.
  • v-model now compiles to modelValue prop + update:modelValue event by default (customizable via model option in defineComponent).
  • vm.$children, vm.$listeners, and vm.$scopedSlots are gone — use slots, emit, and explicit props.
  • Global API is tree-shakable: Vue.use(), Vue.mixin(), Vue.component() are replaced by app instance methods like app.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!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

ArtGPT

ArtGPT

AI image generator for creative art from text prompts.

Stock Market GPT

Stock Market GPT

AI powered investment research for smarter decisions

Popular tool

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

A quick way to handle form validation in Vue.js using Vuelidate. 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. 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) 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? 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? 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? 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) 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) 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.

Related articles