G
G
Gigabait2018-06-25 20:37:39
Vue.js
Gigabait, 2018-06-25 20:37:39

How can I select all elements except the one clicked when clicked?

Tell me how you can select all elements (li) except for the clicked one?
Looping through an array

<ul class="list-group" v-for="item in items">
        <li @click="reciveitems(item)" class="list-group list-group-item"><img :src="item.img" class="rounded mx-auto" :alt="item.name">
          <p class="count position-absolute">{{ item.count }}</p>
          <p class="name position-absolute">{{ item.name }}</p>
        </li>
      </ul>

I also need to maintain indexes in a loop and then pass this index to the function when clicking, this will be the clicked element,
but how can I select the remaining elements?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Shvets, 2018-06-25
@Xuxicheta

we open the Vue documentation and we meet such an example there

<ul id="example-2">
  <li v-for="(item, index) in items">
    {{ parentMessage }} - {{ index }} - {{ item.message }}
  </li>
</ul>

finalizing it
<ul id="example-2">
  <li v-for="(item, index) in items" @click="selectAllExcept(index)">
    {{ parentMessage }} - {{ index }} - {{ item.message }}
  </li>
</ul>

methods: {
 selectAllExcept(index) {
   this.items.forEach((el, i) => {
      if (i !== index) {
        el.selected = true;
      }
   })
 }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question