Cơ BảnVue.js iconVue.js

Options API vs Composition API — khác nhau gì?

Options API (Vue 2 style): tổ chức code theo loại (data, methods, computed, watch).

Composition API (Vue 3): tổ chức code theo logic concern, dùng setup() hoặc <script setup>.

  1. Composition API dễ tái sử dụng logic hơn qua composables
  2. TypeScript support tốt hơn trong Composition API
  3. Options API vẫn được hỗ trợ đầy đủ trong Vue 3

Khuyến nghị dùng Composition API với <script setup> cho project mới.

Xem toàn bộ Vue.js cùng filter theo level & chủ đề con.

Mở danh sách Vue.js