Cơ BảnVue.js iconVue.js

Các cách truyền data giữa components trong Vue?

Vue components giao tiếp qua nhiều cơ chế tùy quan hệ và chiều dữ liệu.

  1. Props (parent → child): dữ liệu đi xuống, one-way
  2. Emits (child → parent): event đi lên, gọi emit()
  3. v-model: two-way binding, kết hợp props + emits
  4. provide/inject: ancestor → descendant, bỏ qua intermediaries
  5. Pinia (recommended) hoặc Vuex (legacy): global state store cho app-wide state
  6. Event bus (ít dùng trong Vue 3): mitt library

Pitfall: tránh emit từ child để trực tiếp modify prop của parent — luôn emit event để parent tự update.

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

Mở danh sách Vue.js