Trung BìnhVue.js iconVue.js

`toRef`, `toRefs`, `toValue` — dùng khi nào?

toRef: tạo ref từ một property của reactive object — giữ reactive connection:

javascript
const state = reactive({ count: 0, name: 'Vue' })
const countRef = toRef(state, 'count') // linked to state.count

toRefs: convert toàn bộ reactive object thành object of refs — dùng khi destructure:

javascript
const { count, name } = toRefs(state)

toValue (Vue 3.3+): unwrap ref hoặc getter — dùng trong composables để accept cả ref và plain value:

javascript
function useFeature(id: MaybeRefOrGetter<string>) {
  const resolvedId = toValue(id) // unwrap nếu là ref
}

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

Mở danh sách Vue.js