No More Posting New Topics!

If you have a question or an issue, please start a thread in our Github Discussions Forum.
This forum is closed for new threads/ topics.

Navigation

    Quasar Framework

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    @click does not fire with q-btn

    Help
    3
    4
    2698
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • J
      justin52 last edited by

      Hi

      I’m new to Quasar and I’m trying to use the @click on a q-btn it doesn’t seem to fire. I’m working with an SPA dev mode. Button show and you can click it but it doesn’t show an alert.

      <q-btn-group flat>
      <q-btn flat color=“brown” size=“lg” align=“right” label=“WATCHING” @click=“alert(‘hello world’)” />
      </q-btn-group>

      Thanks

      1 Reply Last reply Reply Quote 0
      • O
        ouaR last edited by

        this example will find for a method called “alert” in your vue component methods.
        Try this instead:
        <q-btn flat color=“brown” size=“lg” align=“right” label=“WATCHING” @click=“() => alert(‘hello world’)” />
        or use a new method.

        1 Reply Last reply Reply Quote 0
        • s.molinari
          s.molinari last edited by s.molinari

          It doesn’t work because Vue looks for the component instance method “alert” and since it isn’t there, throws an error. You should have seen this in your console, once clicking your button.

          a3214771-14ca-4ddc-8321-ec8b2fe537a9-image.png

          You can do arbitrary JavaScript as this example shows. But methods need to be an instance method.

          https://codepen.io/smolinari/pen/qBEPRPB?editors=1010

          (last button)

          Btw, @ouaR your suggestion doesn’t work either, as the example also shows. The same error happens.

          Makes sense too, as you’d want to do more in your click handler than just show an alert, right? 😁

          Scott

          1 Reply Last reply Reply Quote 0
          • J
            justin52 last edited by

            Hi, I re-installed the quasar cli and now it works. I can only assume I had some package dependency that was causing the issue. Thanks for the responses.

            1 Reply Last reply Reply Quote 0
            • First post
              Last post