1

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!

1
  • share exact object ? Commented Jun 18, 2018 at 7:52

1 Answer 1

2

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.

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

2 Comments

I would also guess the data looks like this, but I think it's more likely OP has made a mistake like mixing up dot and bracket notation and that subject is actually the array - but as you say, we need to see the data first. (Maybe it's a little misleading calling your object myarr, but that's a very minor note - you've got my point.)
Great! I'll try this. Thank you so much.

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.