naive-ui
naive-ui copied to clipboard
docs: Config Provider 提供 component-options 的说明
This function solves the problem (这个功能解决的问题)
当我尝试整体替换 Empty 的默认图标(包括NEmpty、NSelect、NDataTable等组件)的表现形式时,在官网发现可以通过 Slots 插槽修改,但是过于麻烦,每个组件都需要修改一遍。
通过源码发现,在 Empty.tsx 文件中,使用 inject 注入了 Config Provider 的 mergedComponentPropsRef 相关属性。
https://github.com/TuSimple/naive-ui/blob/f4a7c0e224c4abe3f15f6e5abc63578b67cb05e2/src/empty/src/Empty.tsx#L54-L58
通过尝试,可以使用如下方式实现统一替换
<template>
<NConfigProvider :component-options="componentOptions">
</NConfigProvider>
</template>
<script setup>
const componentOptions = ref<GlobalComponentConfig | undefined>({
Empty: {
renderIcon: () => 'your icon'
}
})
</script>
Expected API (期望的 API)
希望在 Config Provider 提供类似说明,避免在源码中寻找解决方案。
这个方法目前是实验阶段,正式发布前可能会存在 breaking change,所以现阶段不建议使用。我们会考虑加速这个功能的开发。
抄送 @07akioni
这个东西暂时不会放到文档里面,目前还不计划作为公开特性
这个东西暂时不会放到文档里面,目前还不计划作为公开特性
已经两年了,这个特性还在,是稳定了吗?