0

I want to collect the data from input with v-model on nested loop, but idk how to do it cause i'm new in Vue.
Here's the code for the component :

        <div
            class="date-item"
            v-for="(day,index) in dateList"
        >
          <div class="mt-4">
            <div class="form-group">
              <ul class="list-task">
                <li v-for="(n,n_key) in 10" :key="n_key">
                  <base-input
                      :id="'input-text'+n"
                      :type="'text'"
                      :disabled="day.isPastDay"
                  />
                </li>
              </ul>
            </div>
          </div>
        </div>

Anyone can help how i created a v-model and data variable for this case ?
4
  • in 10 is not a model, what are you trying to bind to? Commented Jun 13, 2021 at 18:54
  • stackoverflow.com/questions/43364487/… this would help Commented Jun 13, 2021 at 18:57
  • @LawrenceCherone i'm still trying to collect data from each input Commented Jun 13, 2021 at 18:59
  • @DeepinderSingh thanks, but mine is have 2 loop for the input, so it just change the entire of 10 inputs Commented Jun 13, 2021 at 19:02

1 Answer 1

1

With v-model="day.inputs[n_key]"

new Vue({
  el: '#app',
  data: () => ({
    dateList: [{
      isPastDay: false,
      inputs: []
    }]
  })
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.14/vue.min.js"></script>

<div id="app">
  <div class="date-item" v-for="(day,index) in dateList">
    <div class="mt-4">
      <div class="form-group">
        <ul class="list-task">
          <li v-for="(n,n_key) in 10" :key="n_key">
            <input type="text" v-model="day.inputs[n_key]" :disabled="day.isPastDay" />
          </li>
        </ul>
      </div>
    </div>
  </div>
  
  <pre>{{ dateList }}</pre>
</div>

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.