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.counttoRefs: 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
}toRef: creates a ref from a property of a reactive object — maintains reactive connection:
javascript
const state = reactive({ count: 0, name: 'Vue' })
const countRef = toRef(state, 'count') // linked to state.counttoRefs: converts the entire reactive object into an object of refs — use when destructuring:
javascript
const { count, name } = toRefs(state)toValue (Vue 3.3+): unwraps a ref or getter — use in composables to accept both ref and plain values:
javascript
function useFeature(id: MaybeRefOrGetter<string>) {
const resolvedId = toValue(id) // unwraps if ref
}