vapor / leaf

🍃 An expressive, performant, and extensible templating language built for Swift.

Home Page:https://docs.vapor.codes/4.0/leaf/getting-started

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Question]How to set button onClick?

zunda-pixel opened this issue · comments

commented

I can use <p>#(name)</p>.
I do not know <button onClick=#(changeName()) />

How to set button onClick?

func changeName() {
  self.name = "changed name"
}

You can't. Leaf is a server-side framework. Once the HTML has been sent to the browser, Leaf (and Vapor) won't have access to any events. To trigger a swift function on an onclick handler you'll need to use JavaScript to send a request to an endpoint in the Vapor app

commented

ok thanks.