Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Apply VueUse composables in Vue 3/Nuxt projects to replace custom implementations with battle-tested utilities.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/toRefs.md
1---2category: Reactivity3---45# toRefs67Extended [`toRefs`](https://vuejs.org/api/reactivity-utilities.html#torefs) that also accepts refs of an object.89## Usage1011<!-- eslint-disable array-bracket-spacing -->12<!-- eslint-disable ts/no-redeclare -->1314```ts15import { toRefs } from '@vueuse/core'16import { reactive, ref } from 'vue'1718const objRef = ref({ a: 'a', b: 0 })19const arrRef = ref(['a', 0])2021const { a, b } = toRefs(objRef)22const [a, b] = toRefs(arrRef)2324const obj = reactive({ a: 'a', b: 0 })25const arr = reactive(['a', 0])2627const { a, b } = toRefs(obj)28const [a, b] = toRefs(arr)29```3031## Use-cases3233### Destructuring a props object3435```vue36<script lang="ts">37import { toRefs, useVModel } from '@vueuse/core'3839export default {40setup(props) {41const refs = toRefs(useVModel(props, 'data'))4243console.log(refs.a.value) // props.data.a44refs.a.value = 'a' // emit('update:data', { ...props.data, a: 'a' })4546return { ...refs }47}48}49</script>5051<template>52<div>53<input v-model="a" type="text">54<input v-model="b" type="text">55</div>56</template>57```5859## Type Declarations6061```ts62export interface ToRefsOptions {63/**64* Replace the original ref with a copy on property update.65*66* @default true67*/68replaceRef?: MaybeRefOrGetter<boolean>69}70/**71* Extended `toRefs` that also accepts refs of an object.72*73* @see https://vueuse.org/toRefs74* @param objectRef A ref or normal object or array.75* @param options Options76*/77export declare function toRefs<T extends object>(78objectRef: MaybeRef<T>,79options?: ToRefsOptions,80): ToRefs<T>81```82