V
V
Vyacheslav2017-10-10 21:20:21
Vue.js
Vyacheslav, 2017-10-10 21:20:21

How to v-for in a vue component?

Works:

Vue.component('vue-mark-list', {
  template: '<div>{{marks}}</div>',
  data: function () {
    return {
      marks: {
        1: 1,
        2: 2,
        3: 3
      }
    }
  }
});

Does not work:
Vue.component('vue-mark-list', {
  template: '<div v-for="mark in marks">{{mark}}</div>',
  data: function () {
    return {
      marks: {
        1: 1,
        2: 2,
        3: 3
      }
    }
  }
});

where is the mistake? :)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evgeny Kulakov, 2017-10-10
@nskarl

There is no root element in the second template, wrap it in another div:

<div><div v-for="mark in marks">{{mark}}</div></div>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question