-
Notifications
You must be signed in to change notification settings - Fork 27
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
Javascript with Stipple doesn't work. #288
Comments
I guess that the script executes too early. You have to make sure that the listener is added after the DOM has been established. So you rather need to bind the script to the mounted life cyclehook of Vue. using Stipple.ReactiveTools
@mounted reactives """
<your js code ...>
""" Not sure though, why you don't want to use the classical binding via onclick ... EDIT: ... or the Genie-way with <q-btn v-on:click="Swal.fire({title: 'Stipple Fire!'})"></q-btn> as html or via StippleUI btn("Fire", @click("Swal.fire({title: 'Stipple Fire!'})")) EDIT2: updated the syntax of |
My way of writing the app would be import Stipple
import StippleUI
import Genie
import Stipple.ReactiveTools
import Stipple.ReactiveTools: @in, LittleDict
# @Stipple.vars MyApp begin
# name = "World!"
# end
@ReactiveTools.app MyApp begin
@in name = "World!"
end
Stipple.Layout.add_script("https://cdn.jsdelivr.net/npm/sweetalert2@11")
# bring `Swal` to the context of the model
@ReactiveTools.mounted MyApp """
this.Swal = Swal
"""
# make a nice page based on Quasar elements(StippleUI)
function ui()
Stipple.row(StippleUI.card([
StippleUI.cardsection(StippleUI.textfield("Greeting", :name))
StippleUI.cardsection(Stipple.h6("Hello {{ name }}"))
StippleUI.cardsection(StippleUI.btn("Fire", @Stipple.click("Swal.fire({title: 'Stipple Fire!'})")))
]))
end
Stipple.route("/") do
Stipple.page(class = "container",
@ReactiveTools.init(MyApp),
ui,
"v-cloak"
) |> Stipple.html
end
Stipple.up() Currently |
I have this code in Stipple:
But Sweet Alert's javascript doesn't work. I don't know what I did wrong, I followed the steps in the documentation, but I don't think I did something right.
I could do it like this, with onclick in the button tag:
But I would like to access the script normally.
The text was updated successfully, but these errors were encountered: