D
D
ddd23052020-05-02 17:55:35
JavaScript
ddd2305, 2020-05-02 17:55:35

Why doesn't the Vue JS method work?

I tried to create a tab, but I get this 5ead89022281c876242455.png

HTML error

<div class="callback-img-block__green-round">
   <div class="callback-img-block__img callback-img-block_img_1" @click="cbActive()"></div>
</div>
<div class="callback-img-block__img callback-img-block_img_2 callback-img-block_img_2_pos" @click="cbActive()"></div>
<div class="callback-img-block__img callback-img-block_img_3 callback-img-block_img_3_pos" @click="cbActive()"></div>
<div class="callback-img-block__img callback-img-block_img_4 callback-img-block_img_4_pos" @click="cbActive()"></div>
<div class="callback-img-block__img callback-img-block_img_5 callback-img-block_img_5_pos" @click="cbActive()"></div>
<div class="callback-img-block__img callback-img-block_img_6 callback-img-block_img_6_pos" @click="cbActive()"></div>


vue.js

cbActive: function(event){
  const cbAll = document.querySelectorAll('.callback-person-block');
  for(i=0; i<cbAll.length;i++){
     cbAll[i].classList.remove('callback-person-block_active');
  }
  if(event.target.classList.contains('callback-img-block_img_1')) {
    cbAll[0].classList.add('callback-person-block_active');
  } else if(event.target.classList.contains('callback-img-block_img_2')) {
      cbAll[1].classList.add('callback-person-block_active');
  } else if(event.target.classList.contains('callback-img-block_img_3')) {
      cbAll[2].classList.add('callback-person-block_active');
  } else if(event.target.classList.contains('callback-img-block_img_4')) {
      cbAll[3].classList.add('callback-person-block_active');
  } else if(event.target.classList.contains('callback-img-block_img_5')) {
      cbAll[4].classList.add('callback-person-block_active');
  } else if(event.target.classList.contains('callback-img-block_img_6')) {
      cbAll[5].classList.add('callback-person-block_active');
  }                
}


What it looks like:

5ead89a03b555263352317.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Yarkov, 2020-05-02
@ddd2305

@click="cbActive"
@click="cbActive($event)"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question