import { ViewHolder, VMPanel, View, ViewModel, WRAP_CONTENT, Gravity, Mutable, NativeCall, Text, Color, VLayout, Panel, log, logw, loge, Group, Stack, } from "./index" interface CountModel { count: number add: () => void } class CounterView extends ViewHolder { number = new Text counter = new Text build(root: Group) { const vlayout = new VLayout this.number.textSize = 40 this.number.layoutConfig = { alignment: new Gravity().center() } this.counter = new Text this.counter.text = "点击计数" this.counter.textSize = 20 vlayout.space = 20 vlayout.layoutConfig = { alignment: new Gravity().center() } vlayout.addChild(this.number) vlayout.addChild(this.counter) root.addChild(vlayout) } setNumber(n: number) { this.number.text = n.toString() } setCounter(v: Function) { this.counter.onClick = v } } class CounterVM extends ViewModel { binding(v: CounterView, model: CountModel): void { v.setCounter(model.add) v.setNumber(model.count) } } @Entry class MyPage extends VMPanel{ getVMClass() { return CounterVM } getModel() { return { count: 0, add: function () { this.count++ }, } } getViewHolder() { return new CounterView } @NativeCall log() { log("Hello.HEGO") logw("Hello.HEGO") loge("Hello.HEGO") } }