Web-Component

web 组件类是实现了插件底层运行的接口,组合成类模块的形式来开发Web组件,增强了在组件开发中的约束和一致性

包名:web.components

类名:Component


组件生命周期

当组件在初始化时调用
protected onInitialized():void;

当组件在挂载之前调用
protected onBeforeMount():void;

当组件在挂载之后调用
protected onMounted():void;

当组件在更新之前调用
protected onBeforeUpdate():void;

当组件在更新之后调用
protected onUpdated():void;

当组件在卸载之前调用
protected onBeforeUnmount():void;

当组件在卸载之后调用
protected onUnmounted():void;

当组件在激活之后调用
protected onActivated():void;

当组件在释放之后调用
protected onDeactivated():void;

当组件捕获到错误时调用
protected onErrorCaptured():void;

组件属性接收

是否需要对接收到的属性进行处理
protected receivePropValue<T>(value:T,name:string):T;

接收属性之前,判断是否需要接收此属性,返回true接收否则丢弃
protected beforeReceiveProp(value:any,name:string):boolean;

获取组件、DOM元素

获取一个父级组件
public get parent():Component;

通过过滤器获取一个父级组件
public getParentComponent( filter:boolean | (child?:Component)=>boolean ):Component;

获取子级组件
public get children():Component[];

通过引用名获取组件
public getRefs<T=NodeElementType | NodeElementType[]>(name:string):T;

获取挂载后的实例DOM元素
public get element():HTMLElement;

获取组件属性、配置

获取应用的配置
public getConfig():object;

获取指定名称的属性值
public getAttribute<T>(name:string):T;

获取一个引用数据类型的值
public toValue<T>(value:T):T;

创建虚拟节点

创建一个虚拟节点,对应Vue.h()方法
public createVNode(name:string|Component,data?:VNodeDataConfig,children?:VNode|Component[]):VNode;

组件数据注入

提供指定名称的数据给子级组件使用
public provide(name:string, provider:()=>any):void;

注入父级组件提供的数据
public inject<T=any>(name:string, from?:string, defaultValue?:T):T;

组件属性响应式

观察一个有响应式的数据变化
public watch(name: string, callback:(uewVlaue?,oldValue?)=>void, options?:boolean | {immediate?:boolean,deep?:boolean}):void;

创建一个响应式的属性
public reactive<T>(name:string, value?:T, initValue?:any):T;

创建一个响应式的引用
public reference<T>(value?:T,shallowFlag?:boolean):vue.Ref<T>;

创建一个响应式的数据对象
public observable<T extends object>(target:T):T;

组件内部方法

在下一个执行期回调
public nextTick(callback:()=>void):void;

强制更新当前组件
public forceUpdate();

实现渲染方法
protected render():VNode | Component;

使用当前上下文,处理一个有异步的函数,并返回执行结果和重置上下文的函数
protected withAsyncContext<T=any>(handler:()=>Promise<T>):[Promise<T>, ()=>void]

页面路由对象

获取当前页面的路由对象
public getRoute():web.components.Route | null;

组件事件

组件内部通讯事件,通常用于组件的属性变化

监听一个指定类型的事件
public on(type: string, listener:(...args)=>void):void;

断开一个指定类型的事件
public off(type: string, listener?:(...args)=>void):void;

触发一个指定类型的事件
public emit(type: string, ...args?:any[]):void;

组件外部通讯事件,包括代理到DOM元素的事件

添加一个事件
public addEventListener(type: string, listener: (event?:Event)=>void):this;

触发一个事件
public dispatchEvent(event: Event):boolean;

移除一个事件
public removeEventListener(type: string, listener?: (event?:Event)=>void):boolean;

判断是否存在指定的事件
public hasEventListener(type: string, listener?: (event?:Event)=>void):boolean;