英文:
Vugu (Go) framework: @click event is not working
问题
这是一个在Vugu文档中显示的示例,但似乎无法正常工作。
Toggle函数没有被调用。
</head>
<body>
<div id="root">
<div>
<div vg-if='c.Show'>I am here!</div>
<button @click='c.Toggle()'>Toggle me Silly</button>
</div>
<components:Header></components:Header>
<vg-comp expr="c.Body"></vg-comp>
<components:Footer></components:Footer>
</div>
</body>
</html>
<script type="application/x-go">
import "github.com/vugu/vgrouter"
import "log"
type Root struct {
vgrouter.NavigatorRef
Body vugu.Builder // main body content
AutoReload bool // set to true during dev
Show bool `vugu:"data"`
}
func (c *Root) Init(ctx vugu.InitCtx) {
log.Println(c.AutoReload)
log.Println(c.Show)
}
func (c *Root) Toggle() {
c.Show = !c.Show
log.Println(c.Show)
}
</script>
英文:
This is an example as shown in the Vugu docs, yet it doesn't seem to work.
https://www.vugu.org/doc/dom-events
The Toggle function does not get called.
</head>
<body>
<div id="root">
<div>
<div vg-if='c.Show'>I am here!</div>
<button @click='c.Toggle()'>Toggle me Silly</button>
</div>
<components:Header></components:Header>
<vg-comp expr="c.Body"></vg-comp>
<components:Footer></components:Footer>
</div>
</body>
</html>
<script type="application/x-go">
import "github.com/vugu/vgrouter"
import "log"
type Root struct {
vgrouter.NavigatorRef
Body vugu.Builder // main body content
AutoReload bool // set to true during dev
Show bool `vugu:"data"`
}
func (c *Root) Init(ctx vugu.InitCtx) {
log.Println(c.AutoReload)
log.Println(c.Show)
}
func (c *Root) Toggle() {
c.Show = !c.Show
log.Println(c.Show)
}
</script>
答案1
得分: 0
如果你删除与vgrouter
相关的内容,它就可以工作。
</head>
<body>
<div id="root">
<div>
<div vg-if='c.Show'>我在这里!</div>
<button @click='c.Toggle()'>Toggle me Silly</button>
</div>
</div>
</body>
</html>
<script type="application/x-go">
import "log"
type Root struct {
Show bool `vugu: "data"`
}
func (c *Root) Toggle() {
c.Show = !c.Show
log.Println(c.Show)
}
</script>
所以请注意如何添加vgrouter
。
英文:
If you remove things that are related to vgrouter
it works.
</head>
<body>
<div id="root">
<div>
<div vg-if='c.Show'>I am here!</div>
<button @click='c.Toggle()'>Toggle me Silly</button>
</div>
</div>
</body>
</html>
<script type="application/x-go">
import "log"
type Root struct {
Show bool `vugu: "data"`
}
func (c *Root) Toggle() {
c.Show = !c.Show
log.Println(c.Show)
}
</script>
So pay attention to how you add vgrouter
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论