Cơ BảnVue.js iconVue.js

Các directive phổ biến trong Vue: v-if, v-show, v-for, v-model, v-bind, v-on?

Vue directives là các HTML attribute đặc biệt gắn kết reactive behavior vào DOM.

  • Phổ biến nhất: v-if/v-else/v-else-if: điều kiện render, xóa/tạo DOM thật. v-show: ẩn bằng display:none, DOM vẫn tồn tại. v-for: loop render, luôn cần :key. v-model: two-way binding cho input. v-bind (:attr): bind attribute động. v-on (@event): gắn event listener.

Pitfall: v-if và v-for không nên dùng trên cùng element — v-if ưu tiên cao hơn v-for trong Vue 3 (ngược với Vue 2), dùng <template v-for> bọc bên ngoài.

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

Mở danh sách Vue.js