N
N
nastya_zholudeva2018-08-21 14:20:53
Vue.js
nastya_zholudeva, 2018-08-21 14:20:53

How to make a class added and removed with v-for only on click on this element?

How to make a class added and removed with v-for only on click on this element? I tried here , but it turned out that if I click on another element, then the open one closes, and I need it to close only if I click on it

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2018-08-21
@nastya_zholudeva

Add to each element of the array a property responsible for the presence of a class:

todos: [
  { open: false, ... },
  { open: false, ... },
  ...
],

Toggle the value of this property on click:
@click="todo.open = !todo.open"
Assign a class depending on the value:
:class="{ 'dropdown-active': todo.open }"
https://jsfiddle.net/2ef8yojn/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question