Cơ BảnVue.js iconVue.js

`<script setup>` là gì? Lợi ích so với `setup()` thông thường?

<script setup> là syntactic sugar cho Composition API — tất cả code bên trong tự động expose ra template mà không cần return.

  1. Gọn hơn: không cần export default, không cần return
  2. Hiệu năng tốt hơn: compiler tối ưu hóa tốt hơn
  3. TypeScript integration tốt hơn
  4. defineProps, defineEmits, defineExpose thay cho options props/emits

Pitfall: biến và function trong <script setup> khác file KHÔNG cần export — tự exposed.

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

Mở danh sách Vue.js