ComponentSlots 读取组件的 defineSlots 类型,渲染插槽名、作用域参数类型与说明。
用法
| Slot | Type |
|---|---|
default | {} 默认内容插槽 |
avatar | { src: string; }头像插槽,作用域暴露头像地址 |
:component-slots{slug="TestApi"}
省略 slug 时按当前路由的最后一段查找组件。
编写插槽说明
在 defineSlots 中为每个插槽写 JSDoc,作用域参数的类型会显示在类型列:
components/TestApi.vue
<script setup lang="ts">
defineSlots<{
/**
* 默认内容插槽
*/
default(props?: {}): any
/**
* 头像插槽,作用域暴露头像地址
* @see https://ui.nuxt.com/components/avatar
*/
avatar(props: { src: string }): any
}>()
</script>
API
Props
| Prop | Default | Type |
|---|---|---|
slug | 路由路径的最后一段 | string获取组件插槽的 slug 标识 |
Changelog
No recent changes