コンテンツにスキップ

reactiveOmit

カテゴリ
エクスポートサイズ
381 B
最終更新
先週

リアクティブオブジェクトからフィールドをリアクティブに省略します。

使用法

基本的な使用法

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

const obj = reactive({
  x: 0,
  y: 0,
  elementX: 0,
  elementY: 0,
})

const picked = reactiveOmit(obj, 'x', 'elementX') // { y: number, elementY: number }

述語の使用法

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

const obj = reactive({
  bar: 'bar',
  baz: 'should be omit',
  foo: 'foo2',
  qux: true,
})

const picked = reactiveOmit(obj, (value, key) => key === 'baz' || value === true)
// { bar: string, foo: string }

シナリオ

子にpropsを選択的に渡す

vue
<script setup>
import { reactiveOmit } from '@vueuse/core'

const props = defineProps({
  value: {
    default: 'value',
  },
  color: {
    type: String,
  },
  font: {
    type: String,
  }
})

const childProps = reactiveOmit(props, 'value')
</script>

<template>
  <div>
    <!-- only passes "color" and "font" props to child -->
    <ChildComp v-bind="childProps" />
  </div>
</template>

型宣言

typescript
export type ReactiveOmitPredicate<T> = (
  value: T[keyof T],
  key: keyof T,
) => boolean
export declare function reactiveOmit<T extends object, K extends keyof T>(
  obj: T,
  ...keys: (K | K[])[]
): Omit<T, K>
export declare function reactiveOmit<T extends object>(
  obj: T,
  predicate: ReactiveOmitPredicate<T>,
): Partial<T>

ソース

ソースドキュメント

貢献者

Anthony Fu
Anthony Fu
Doctorwu
丶遠方
Brain777777
qiang

変更履歴

v12.0.0-beta.1 2024/11/21 に
0a9ed - feat!: Vue 2 のサポートを廃止し、バンドルを最適化してクリーンアップ (#4349)
v10.0.0-beta.4 2023/04/13 に
0a72b - feat(toValue): resolveUnreftoValue にリネーム
v10.0.0-beta.2 2023/03/28 に
2e297 - feat: 述語パラメータを追加 (#2849)

MITライセンスの下でリリースされています。