feat: 注释 & api丰富

This commit is contained in:
unanmed 2024-02-03 14:36:29 +08:00
parent 67857841ca
commit 09118b162c

View File

@ -118,6 +118,12 @@ export class MComponent {
return this.h(component, [], config); return this.h(component, [], config);
} }
/**
*
* @param items
* @param map VNodeVNode可以通过Vue.h函数
* MComponent.vNode函数生成
*/
vfor<T>(items: T[] | (() => T[]), map: (value: T, index: number) => VNode) { vfor<T>(items: T[] | (() => T[]), map: (value: T, index: number) => VNode) {
this.content.push({ this.content.push({
type: '@v-for', type: '@v-for',
@ -133,7 +139,7 @@ export class MComponent {
* *
* `slots``vfor.map` * `slots``vfor.map`
* 使使`setup` * 使使`setup`
* setup函 * `setup`
* @param type * @param type
* - dom元素`div` `span` * - dom元素`div` `span`
* - `MComponent` * - `MComponent`
@ -200,6 +206,12 @@ export class MComponent {
return this; return this;
} }
/**
*
* @param fn props和当前级组件
*
* A组件中调用了B组件A组件的画布B组件的画布
*/
onMounted(fn: OnMountedFunction) { onMounted(fn: OnMountedFunction) {
this.onMountedFn = fn; this.onMountedFn = fn;
return this; return this;
@ -255,6 +267,29 @@ export class MComponent {
} }
} }
/**
* VNode
* @param child
* @param mount id
*/
static vNodeS(child: MotaComponent, mount?: number) {
return this.vNode([child], mount)[0];
}
/**
* MComponent实例生成为一个VNode列表
* @param mc VNode的组件
* @param mount id
*/
static vNodeM(mc: MComponent, mount?: number) {
return this.vNode(mc.content, mount);
}
/**
* MComponent内容生成为一个VNode列表
* @param children VNode的内容列表
* @param mount id
*/
static vNode(children: (MotaComponent | VForRenderer)[], mount?: number) { static vNode(children: (MotaComponent | VForRenderer)[], mount?: number) {
const mountNum = mount ?? this.mountNum++; const mountNum = mount ?? this.mountNum++;
@ -330,6 +365,10 @@ export class MComponent {
return res; return res;
} }
/**
* props的真实值props是一个函数
* @param props props
*/
static unwrapProps(props?: Record<string, () => any>): Record<string, any> { static unwrapProps(props?: Record<string, () => any>): Record<string, any> {
if (!props) return {}; if (!props) return {};
const res: Record<string, any> = {}; const res: Record<string, any> = {};