B
B
ByJumping2022-02-15 18:53:10
Vue.js
ByJumping, 2022-02-15 18:53:10

How to get rid of duplicate data in vue method?

Hi there is a component

<div class="form__select_wrapper">
      <div class="form__select_checkbox" v-for="(item, i) in stepOneTitle" :key="item">
        <label @click="changeType(item, i)">
          <input class="form__checkbox" type="checkbox">
          <span class="form__custom_checkbox"></span>
          <span class="form__checkbox_text">{{ item }}</span>
        </label>
      </div>
    </div>


the method itself
changeType(item, i) {
      console.log(item)
      this.$emit('changeType', item);
    }


The item always receives a string, a title. In the future, I need to place this title in an array

. So the console always displays item 2 times. And if I want to add an item to the array using the push method, then it will add it 2 times.

And if you hang click events, for example, on input or span, then everything is fine

. How to get rid of this duplication? I need the click event to hang on the label

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question