修改插件的实现和文档

This commit is contained in:
编码猿
2025-09-19 13:01:26 +08:00
parent 79a0c9a451
commit b3718c4097
10 changed files with 130 additions and 120 deletions

View File

@@ -1,54 +1,45 @@
import { Component, ComponentProps, Hook, useProps, VueComponent } from 'vue3-oop'
import { JSX } from "vue/jsx-runtime";
import { VNodeChild } from "vue";
import { Component, Prop, TSX, Vue } from 'vue-facing-decorator'
interface Props {
text?: string
list?: ListItemType[]
}
interface ListItemType {
id: number
title: string
}
interface HeaderProps {
text?: string;
list: ListItemType[]
slots: {
default: () => JSX.Element;
haveName: () => JSX.Element;
item: (val: ListItemType) => VNodeChild;
}
}
@Component()
export default class Header extends VueComponent<HeaderProps> {
export default class Header extends TSX<Props>()(Vue) implements Props {
// required 的 true or false 需要和 类型中 text的? 对应
static defaultProps: ComponentProps<HeaderProps> = {
text: { default: '默认数值', required: true },
list: { default: () => [] }
};
@Prop({ default: '默认数值' })
text!: string;
@Hook('Mounted')
mounted() {
console.log("this: ", this);
console.log('Header 组件的 mounted 生命周期...')
@Prop()
list!: ListItemType[];
created() {
console.log("created: ", this)
}
render() {
const { text, list } = useProps<HeaderProps>();
return (
<div class="header">
<p>{ text }</p>
{ this.context.slots.default?.() }
{ this.context.slots.haveName?.() }
<p>{ this.text }</p>
{ this.$slots.default?.() }
{ this.$slots.haveName?.() }
<ul>
{
list.map(
this.list.map(
item =>
this.context.slots.item?.(item)
this.$slots.item?.(item)
)
}
</ul>
</div>
)
}
}
}