组件概览
ElfUI 的组件是标准 Custom Element。主线写法是宏组件:顶层 TypeScript 负责逻辑,defineHtml(...) 负责声明模板和组件边界。
ts
import { defineHtml, defineProps } from "@elfui/core";
const props = defineProps<{ label: string }>({
label: { type: String, default: "保存" }
});
export const SaveButton = defineHtml(` <button>${props.label}</button> `);组件能力
| 能力 | 文档 |
|---|---|
| 定义组件 | defineHtml、文件导出、tag 推断 |
| 输入 | Props |
| 输出 | 事件、v-model |
| 内容分发 | 插槽 |
| 跨层共享 | Provide / Inject |
| 命令式访问 | 模板引用、组件暴露 |
| 组合 | 局部组件、动态组件 |
| 复用 | useExtend / useVariant |
推荐顺序
WARNING
先写清楚 props 和事件,再决定是否需要 v-model、插槽、provide/inject 或 expose。组件通信方式不要混用太多,API 越少越稳定。
