[Question]How to set button onClick?
zunda-pixel opened this issue · comments
zunda 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"
}
Tim Condon commented
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
zunda commented
ok thanks.