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 }
场景
有选择地将属性传递给子组件
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>
<!-- 只将 "color" 和 "font" 属性传递给子组件 -->
<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>
Source
贡献者
Anthony Fu
丶远方
Anthony Fu
Doctorwu
Brain777777
qiang
变更日志
v10.0.0-beta.4
on 4/13/20230a72b
- feat(toValue): rename resolveUnref
to toValue
v10.0.0-beta.2
on 3/28/2023