Skip to content

makeDestructurable

使对象和数组同时可同构解构。详细信息请参见 这个博客

¥Make isomorphic destructurable for object and array at the same time. See this blog for more details.

用法

¥Usage

TypeScript 示例:

¥TypeScript Example:

ts
import { makeDestructurable } from '@vueuse/core'

const foo = { name: 'foo' }
const bar = 1024

const obj = makeDestructurable(
  { foo, bar } as const,
  [foo, bar] as const,
)
js
import { makeDestructurable } from '@vueuse/core'
const foo = { name: 'foo' }
const bar = 1024
const obj = makeDestructurable({ foo, bar }, [foo, bar])

用法:

¥Usage:

ts
let { foo, bar } = obj
let [foo, bar] = obj

类型声明

typescript
export declare function makeDestructurable<
  T extends Record<string, unknown>,
  A extends readonly any[],
>(obj: T, arr: A): T & A

源代码

源代码文档

变更日志

No recent changes

VueUse 中文网 - 粤ICP备13048890号