T
T
Tamerlan Godzhiev2018-09-07 13:12:01
Vue.js
Tamerlan Godzhiev, 2018-09-07 13:12:01

How to make 2 arrays in Vue?

Hello. There is such a simple construction in Vue

<ul id="example-1">
  <li v-for="item in items">
    {{ item.message }}
  </li>
</ul>

var example1 = new Vue({
  el: '#example-1',
  data: {
    items: [
      { message: 'Foo' },
      { message: 'Bar' }
    ]
  }
})

This is understandable, but if I want to create another list and display an arc array and its elements in it?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander, 2018-09-07
@tamerlan676

You just need to create a second list and a separate ul for it

<div id="example-1">
<ul>
  <li v-for="item in items1">
    {{ item.message }}
  </li>
</ul>
<ul>
  <li v-for="item in items2">
    {{ item.message }}
  </li>
</ul>
</div>

var example1 = new Vue({
  el: '#example-1',
  data: {
    items1: [
      { message: 'Foo' },
      { message: 'Bar' }
    ],
    items2: [
      { message: 'Foo' },
      { message: 'Bar' }
    ]
  }
})

M
mShpakov, 2018-09-07
@mShpakov

var example1 = new Vue({
  el: '#example-1',
  data: {
    items: [
      { message: 'Foo' },
      { message: 'Bar' }
    ],
    newItems: [
      { message: 'Foo' },
      { message: 'Bar' }
    ],
  }
})

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question