-
-
Notifications
You must be signed in to change notification settings - Fork 391
Description
//hello.go
import (
"fmt"
"github.com/maxence-charriere/go-app/v10/pkg/app"
"time"
)
type Hello struct {
app.Compo
name string
}
func (h *Hello) OnNav(ctx app.Context) {
h.name = fmt.Sprintf("初始值%s", time.Now().Format("2006-01-02 15:04:05"))
}
func (h *Hello) Render() app.UI {
return app.Div().Styles(map[string]string{
"display": "flex",
"flex-direction": "column",
}).Body(
app.Input().Value(h.name).OnChange(h.ValueTo(&h.name)),
NewMyInput(h.name, "测试01", &h.name),
app.Button().Text("更新").OnClick(func(ctx app.Context, e app.Event) {
h.name = "被更新" + fmt.Sprintf("%v", time.Now().UnixMilli())
ctx.Update()
}),
)
}
type MyInput struct {
app.Compo
value string
placeholder string
bindValue *string
}
func NewMyInput(value, placeValue string, bv *string) *MyInput {
return &MyInput{
Compo: app.Compo{},
value: value,
placeholder: placeValue,
bindValue: bv,
}
}
func (self *MyInput) Render() app.UI {
return app.Div().Body(
app.Input().Value(self.value).Placeholder(self.placeholder).
OnChange(self.ValueTo(self.bindValue)),
)
}