interface?State?{
????price:?number;
????count:?number;
}
export?default?class?ClassT?extends?BaseComponent<{},?State>?{
????constructor(props)?{
????????super(props);
????????this.state?=?{
????????????price:?100,
????????????count:?1
????????}
????????this.onIncrease?=?this.onIncrease.bind(this);
????????this.onDecrease?=?this.onDecrease.bind(this);
????}
????componentDidMount()?{
????????ClassT.printSomething();
????????ClassT.asyncPrintSomething();
????????this.doSomethings();
????????this.asyncDoSomethings();
????}
????@catchMethod({?message:?"printSomething?error",?toast:?true?})
????static?printSomething()?{
????????throw?new?CatchError("printSomething?error:?主動拋出");
????????console.log("printSomething:",?Date.now());
????}
????@catchMethod({?message:?"asyncPrintSomething?error",?toast:?true?})
????static?async?asyncPrintSomething()?{
????????const?{?run?}?=?delay(1000);
????????await?run();
????????throw?new?CatchError("asyncPrintSomething?error:?主動拋出");
????????console.log("asyncPrintSomething:",?Date.now());
????}
????@catchGetter({?message:?"計算價格失敗",?toast:?true?})
????get?totalPrice()?{
????????const?{?price,?count?}?=?this.state;
????????//?throw?new?Error("A");
????????return?price?*?count;
????}
????@catchMethod("增加數(shù)量失敗")
????async?onIncrease()?{
????????const?{?run?}?=?delay(1000);
????????await?run();
????????this.setState({
????????????count:?this.state.count?+?1
????????})
????}
????@catchMethod("減少數(shù)量失敗")
????onDecrease()?{
????????this.setState({
????????????count:?this.state.count?-?1
????????})
????}
????@catchInitializer({?message:?"catchInitializer?error",?toast:?true?})
????doSomethings?=?()?=>?{
????????console.log("do?some?things");
????????throw?new?CatchError("catchInitializer?error:?主動拋出");
????}
????@catchInitializer({?message:?"catchInitializer?async?error",?toast:?true?})
????asyncDoSomethings?=?async?()?=>?{
????????const?{?run?}?=?delay(1000);
????????await?run();
????????throw?new?CatchError("catchInitializer?async?error:?主動拋出");
????}
????render()?{
????????const?{?onIncrease,?onDecrease?}?=?this;
????????const?totalPrice?=?this.totalPrice;
????????return?????????????padding:?"150px",
????????????lineHeight:?"30px",
????????????fontSize:?"20px"
????????}}>
????????????
價格:{
this.state.price}<
/div>
????????????數(shù)量:1div>
????????????
????????????????