Introduction to Vue 3, Its New Features and Composition API

This article provides a comprehensive overview of Vue 3—including its release details, performance gains, core architectural changes such as Proxy‑based reactivity, TypeScript support, the new Composition API (setup, ref, reactive, computed, watch, watchEffect), updated lifecycle hooks, new built‑in components like Fragment, Teleport and Suspense, project scaffolding with Vue‑CLI or Vite, and migration considerations from Vue 2.

php Courses
php Courses
php Courses
Introduction to Vue 3, Its New Features and Composition API

Vue 3 was officially released on September 18 2020 (code‑named “One Piece”), after more than two years of development, over 2 600 commits, 30+ RFCs, 600+ PRs and contributions from 99 developers.

Performance improvements include a 41% reduction in bundle size, a 55% faster initial render, a 133% faster update render, and a 54% reduction in memory usage.

The core source was upgraded: Vue 3 replaces Object.defineProperty with Proxy for reactivity, rewrites the virtual DOM and adds Tree‑Shaking support, and provides first‑class TypeScript integration.

Key new features are delivered through the Composition API: setup() becomes the entry point, ref() creates reactive primitive values, reactive() creates deep reactive objects, computed() defines derived state, watch() and watchEffect() observe changes, and lifecycle hooks are available as composable functions (e.g., onMounted, onBeforeUnmount).

Creating a Vue 3 project can be done with vue create vue_test (Vue‑CLI) or with Vite using npm init vite-app <project-name>, followed by npm install and npm run dev.

Examples of ref and reactive usage:

import { ref } from "vue";<br/>const count = ref(0);
import { reactive } from "vue";<br/>const state = reactive({ name: "Vue", version: 3 });
watch(count, (newVal, oldVal) => { console.log('count changed', newVal, oldVal); }, { immediate: true });

demonstrates the watch API, while watchEffect(() => { console.log(state.name); }); shows the effect‑based watcher.

Additional utilities include toRef / toRefs for exposing single properties, shallowReactive / shallowRef for shallow reactivity, readonly / shallowReadonly for immutable data, markRaw to exclude objects from reactivity, and customRef for building debounced refs.

Vue 3 also introduces new built‑in components: Fragment removes the need for a single root element, Teleport moves markup to a different part of the DOM, and Suspense provides fallback UI while async components load.

Migration changes from Vue 2 include renamed lifecycle hooks ( beforeDestroybeforeUnmount, destroyedunmounted), removal of keyCode modifiers and v-on.native, deprecation of filters, and the shift of global APIs from Vue.xxx to the application instance ( app.xxx).

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

frontendJavaScriptreactiveComposition APIViteVue3
php Courses
Written by

php Courses

php中文网's platform for the latest courses and technical articles, helping PHP learners advance quickly.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.