reactiveOmit

reactiveOmit

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

使用法

基本的な使用法

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 }

条件付き使用法

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 }

シナリオ

子コンポーネントにプロパティを選択的に渡す

<script setup lang="ts">
import { reactiveOmit } from '@vueuse/core'

const props = defineProps<{
  value: string
  color?: string
  font?: string
}>()

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

<template>
  <div>
    <!-- "color" と "font" プロパティのみを子コンポーネントに渡す -->
    <ChildComp v-bind="childProps" />
  </div>
</template>