Reka UI logoReka
backdrop
实用工具

useEmitAsProps

将 emits 转换为类似于 props 的对象

当您为组件构建包装器时,最大的痛点之一是将组件发出的所有事件转发出去。

通过使用这个 composable,它会将您声明的 emits 转换为 Vue 组件可接受的处理程序对象。

用法

vue
<script setup lang="ts">
import { useEmitAsProps } from 'reka-ui'

const emits = defineEmits<CompEmitType>()
const emitsAsProps = useEmitAsProps(emits)
</script>

<template>
  <Comp v-bind="emitsAsProps">
    ...
  </Comp>
</template>