Trung BìnhVue.js iconVue.js

`storeToRefs` là gì? Tại sao cần?

Pinia store là reactive object — destructuring trực tiếp sẽ mất reactivity (tương tự reactive()). storeToRefs() convert state và getters thành refs để destructure an toàn: const { count, name } = storeToRefs(store).

  • Methods (actions) không cần storeToRefs — destructure thường: const { increment } = store.

Pitfall: nếu dùng storeToRefs với methods, chúng trở thành refs — không gọi được như function.

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

Mở danh sách Vue.js