hayumi kuran
hayumi kuran

Reputation: 431

Pass parameter as a array's element [Vuejs]

I have vuejs code like below,

<div v-for="vl in 3">
  {{ data[subject.vl] }}
</div>

I want to display data[subject.0], data[subject.1], data[subject.2] and data[subject.3]

Any ideas? Thanks!

Upvotes: 1

Views: 154

Answers (1)

Niklesh Raut
Niklesh Raut

Reputation: 34914

You need to pass array inside v-for directive and use myarr['subject.'+vl] to make proper key

new Vue({
  el:'#app',
  data:{
    myarr:{
      "subject.0":"Array 0 value",
      "subject.1":"Array 1 value",
      "subject.2":"Array 2 value",
      "subject.3":"Array 3 value",
    }
  }
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.16/vue.js"></script>
<div id="app">
  <div v-for="v1 in [0,1,2,3]">{{myarr['subject.'+v1]}}</div>
</div>

share exact object, to get another alternative or better solution.

Upvotes: 2

Related Questions