I
I
Igor Koch2018-03-16 20:07:15
JavaScript
Igor Koch, 2018-03-16 20:07:15

Is it possible to inject variables into v-bind?

// Два раза в одном элементе вызывается "specializations.indexOf(sub_category.id)" 
// Как в элементе сохранить результат первого вычиcления и не вызывать два раза одну функцию? 

// Например:
<div class="col-md-6" v-for="sub_category in category.sub_categories" :key="sub_category.id">
  <div class="form-check form-check-inline">
    <input 
      class="form-check-input" 
      type="checkbox"
      @change="updateSpecialization(sub_category.id, $event.target.checked)"
      :disabled="user.specializations.length >= 5 && specializations.indexOf(sub_category.id) < 0"
      :checked="specializations.indexOf(sub_category.id) >= 0"
      :id="`sub-cat-${sub_category.id}`">
    <label class="form-check-label" :for="`sub-cat-${sub_category.id}`">
      {{ sub_category.title }}
    </label>
  </div>
</div>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Shvets, 2018-03-16
@amux

computed
And if you need to store something "in an element", then it's time to separate it into a separate component.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question