Component class是当前组件的构建函数,会在该组件实例化时调用。
开发者需要通过继承Component 来开发一个自己的组件逻辑类。
Component包括了一个组件的构建、生命周期、state设置方法等。
xml:
<div class="x-button" onClick="buttonClick">{{text}}</div>
.ts
import { Event, Props, console, Component, Target } from "waft";
import { JSON, JSONObject } from "waft-json";
export class XButton extends Component{
constructor(props: Props){
super(props);
}
buttonClick(e: Event): void{
this.props.dispatch("onTap");
}
deriveDataFromProps(nextProps: JSONObject): void{
console.log("props:" + nextProps.toString())
}
willMount(attribute: JSONObject):void{
console.log('component willMount:' + attribute.toString());
}
didMount():void{
console.log('component didMount');
}
didUnmount():void{
console.log('component didUnmount');
}
}