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

    Can I modify a button when iterating?

    Help
    button
    4
    4
    134
    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.
    • W
      wpq last edited by

      I have the following buttons:

         <q-btn
            color="blue"
            class="q-ma-sm"
            size="sm"
            v-for="tag in allTags"
            @click="tag.set=!tag.set"
          >
            {{tag}}
          </q-btn>
      

      allTags is an Array with elements such as {tag: "hello", set: true}.

      As expected, I get a row of buttons but clicking on them does not change the set property.

      Is it possible to modify the value of a property while iterating this way?

      dobbel metalsadman S 3 Replies Last reply Reply Quote 0
      • dobbel
        dobbel @wpq last edited by

        @wpq

        Your problem is that Vue(2) has reactivity need to knows when altering the values inside objects and arrays.

        See:
        https://vuejs.org/v2/guide/reactivity.html

        So instead of:

        @click="tag.set=!tag.set"
        

        you have to do something like this:

        // Vue.set(object, propertyName, value)
        Vue.set(tag, 'set', !tag.set)
        

        Btw not sure if Vue is availible inside the vue template, so you might need to use a clickHandler function.

        1 Reply Last reply Reply Quote 1
        • metalsadman
          metalsadman @wpq last edited by

          @wpq you could just be missing a :key there.

          1 Reply Last reply Reply Quote 1
          • S
            suleiman_as @wpq last edited by suleiman_as

            @wpq You could setup a method and pass the tag or index onclick and set it from the method.
            Edit: and don’t forget the :key

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