reactiveOmit
リアクティブオブジェクトからフィールドをリアクティブに省略します。
使用法
基本的な使用法
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>
ソース
貢献者
変更履歴
v12.0.0-beta.1
2024/11/21 にv10.0.0-beta.4
2023/04/13 に0a72b
- feat(toValue): resolveUnref
を toValue
にリネームv10.0.0-beta.2
2023/03/28 に