Replies: 4 comments 6 replies
-
This looks more like a vueuse function than a core utility |
Beta Was this translation helpful? Give feedback.
1 reply
-
const { name, age } = toRefs(objRef.value) |
Beta Was this translation helpful? Give feedback.
5 replies
-
https://github.com/hcg1023/vue-ref2reactive |
Beta Was this translation helpful? Give feedback.
0 replies
-
Can we add a new overload to toRef and toRefs to support multi-level progression of objects function toRef<T extends object, K extends keyof T, K2 extends keyof T[K]>(obj: T, keys: [K, K2?]): K2 extends keyof T[K] ? T[K][K2] : T[K] {
}
const nameRef = toRef({ value: { name: 'new' } }, ['value', 'name'])
nameRef.value // 'new'
const objRef = ref({ name: 'ref', age: 16 })
const { name, age } = toRefs(objRef, ['value'])
name.value // 'ref'
age.value // 16 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
What problem does this feature solve?
In Vue3, because the object generated by reactive can not be reassigned, we generally use the method of
const objRef = ref(object)
to define an object that needs to be assigned repeatedly. However, such a definition will make it cumbersome to read the attributes of the object, for example:I hope to provide a quick reading method through toRefs, for example:
What does the proposed API look like?
I have realized this function, but I have added a new api, which does not replace the original toRefs, so I hope to discuss with you whether it exists and if so, what does it look like? If appropriate, I will mention a PR. I put the corresponding code in my repository.
https://github.com/hcg1023/vue3-dnd/blob/main/lib/internals/toReactive.ts
Beta Was this translation helpful? Give feedback.
All reactions