Vugu(Go)框架:@click事件不起作用

huangapple go评论91阅读模式
英文:

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.

&lt;/head&gt;
    &lt;body&gt;
        &lt;div id=&quot;root&quot;&gt;
            &lt;div&gt;
                &lt;div vg-if=&#39;c.Show&#39;&gt;I am here!&lt;/div&gt;
                &lt;button @click=&#39;c.Toggle()&#39;&gt;Toggle me Silly&lt;/button&gt;
            &lt;/div&gt;
            &lt;components:Header&gt;&lt;/components:Header&gt;
            &lt;vg-comp expr=&quot;c.Body&quot;&gt;&lt;/vg-comp&gt;
            &lt;components:Footer&gt;&lt;/components:Footer&gt;
        &lt;/div&gt;
    &lt;/body&gt;
&lt;/html&gt;

&lt;script type=&quot;application/x-go&quot;&gt;

import &quot;github.com/vugu/vgrouter&quot;
import &quot;log&quot;

type Root struct {
    vgrouter.NavigatorRef
    Body vugu.Builder // main body content
    AutoReload bool // set to true during dev
    Show bool `vugu:&quot;data&quot;`
}

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)
}

&lt;/script&gt;

答案1

得分: 0

如果你删除与vgrouter相关的内容,它就可以工作。

&lt;/head&gt;
    &lt;body&gt;
        &lt;div id=&quot;root&quot;&gt;
            &lt;div&gt;
                &lt;div vg-if=&#39;c.Show&#39;&gt;我在这里&lt;/div&gt;
                &lt;button @click=&#39;c.Toggle()&#39;&gt;Toggle me Silly&lt;/button&gt;
            &lt;/div&gt;

        &lt;/div&gt;
    &lt;/body&gt;
&lt;/html&gt;

&lt;script type=&quot;application/x-go&quot;&gt;

import &quot;log&quot;

type Root struct {
    Show bool `vugu: &quot;data&quot;`
}


func (c *Root) Toggle() { 
    c.Show = !c.Show
    log.Println(c.Show)
}

&lt;/script&gt;

检查一下:
https://play.vugu.org/?p=H4sIAAAAAAAC_2yQwU7DMBBE7_sVU1_aIrW5I8fiyg1RPqCu4zoWTjZyN4Wq4t9RYhVExW12vG-0Y1213jaGAEAfuLkUOY9NPCM2tcrMon7929tf54c4h0081ku33bX8sTTPsB1an_1CV_9Dh1GEezy5FN37BL5xCMmv1ktTFDqPXUzpoquye3dLyaW7uchSSVetdMkQ6ZPLcRDIZfC1ssOQorMSua8-N4GVIYrdwFmgEgdFNO3hlVlwkjw6wXXOnarhwJywP49hfIRqrFi1py8iOo69w8rhYeLWuLXBFTNbPgY1FkXNZuKwfcmxl9Svir2esnRV7jXfAQAA__8KPfQspwEAAA%3D%3D

所以请注意如何添加vgrouter

英文:

If you remove things that are related to vgrouter it works.

&lt;/head&gt;
    &lt;body&gt;
        &lt;div id=&quot;root&quot;&gt;
            &lt;div&gt;
                &lt;div vg-if=&#39;c.Show&#39;&gt;I am here!&lt;/div&gt;
                &lt;button @click=&#39;c.Toggle()&#39;&gt;Toggle me Silly&lt;/button&gt;
            &lt;/div&gt;

        &lt;/div&gt;
    &lt;/body&gt;
&lt;/html&gt;

&lt;script type=&quot;application/x-go&quot;&gt;

import &quot;log&quot;

type Root struct {
    Show bool `vugu: &quot;data&quot;`
}


func (c *Root) Toggle() { 
    c.Show = !c.Show
    log.Println(c.Show)
}

&lt;/script&gt;

Check it:
https://play.vugu.org/?p=H4sIAAAAAAAC_2yQwU7DMBBE7_sVU1_aIrW5I8fiyg1RPqCu4zoWTjZyN4Wq4t9RYhVExW12vG-0Y1213jaGAEAfuLkUOY9NPCM2tcrMon7929tf54c4h0081ku33bX8sTTPsB1an_1CV_9Dh1GEezy5FN37BL5xCMmv1ktTFDqPXUzpoquye3dLyaW7uchSSVetdMkQ6ZPLcRDIZfC1ssOQorMSua8-N4GVIYrdwFmgEgdFNO3hlVlwkjw6wXXOnarhwJywP49hfIRqrFi1py8iOo69w8rhYeLWuLXBFTNbPgY1FkXNZuKwfcmxl9Svir2esnRV7jXfAQAA__8KPfQspwEAAA%3D%3D

So pay attention to how you add vgrouter

huangapple
  • 本文由 发表于 2022年1月18日 19:25:22
  • 转载请务必保留本文链接:https://go.coder-hub.com/70754833.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定