Primitive
将 Reka 的功能组合到其他元素类型或您自己的 Vue 组件上。
在构建组件时,有时您可能希望允许用户将某些功能组合到底层元素或其他元素上。这正是 Primitive 发挥作用的地方,它将这种能力开放给用户。
API 参考
| Prop | Default | Type |
|---|---|---|
as | div | string | Component当前元素应渲染成的元素或组件。可被 |
asChild | false | boolean将默认渲染的元素更改为作为子元素传递的元素,合并它们的属性和行为。 |
用法
更改 as 值
如果您想更改默认渲染的元素或组件,可以在定义 props 时设置默认的 as。
vue
<script setup lang="ts">
import type { PrimitiveProps } from 'reka-ui'
import { Primitive } from 'reka-ui'
const props = withDefaults(defineProps<PrimitiveProps>(), {
as: 'span'
})
</script>
<template>
<!-- 现在此元素将默认渲染为 `span` -->
<Primitive v-bind="props">
...
</Primitive>
</template>渲染 asChild
将默认渲染的元素更改为作为子元素传递的元素,合并它们的属性和行为。
阅读我们的 组合指南以了解更多详情。
