Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question]How to set button onClick? #201

Closed
zunda-pixel opened this issue Dec 27, 2021 · 2 comments
Closed

[Question]How to set button onClick? #201

zunda-pixel opened this issue Dec 27, 2021 · 2 comments

Comments

@zunda-pixel
Copy link

zunda-pixel commented Dec 27, 2021

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

How to set button onClick?

func changeName() {
  self.name = "changed name"
}
@0xTim
Copy link
Member

0xTim commented Dec 29, 2021

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

@0xTim 0xTim closed this as completed Dec 29, 2021
@zunda-pixel
Copy link
Author

ok thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants