J
J
Junior Development2020-05-15 18:45:12
Vue.js
Junior Development, 2020-05-15 18:45:12

How to replace object name in vue.js loop?

The question was formulated rather clumsily, but the essence is as follows.
When you click on the li tag, you need to replace blockItems.items1 with blockItems.items2, and when you click again, replace blockItems.items2 with blockItems.items1

<ul class='items'>
    <li class='item' @click='replacItems' v-for='item in blockItems.items1'>
      <div class='item__title'>{{ item.title }}</div>
    </li>
  </ul>


blockItems: {
   items1: [
      {title: 'Загловок 1'},
      {title: 'Заголовк 2'},
   ],
   items2: [
      {title: 'Загловок 3'},
      {title: 'Заголовк 4'},
   ]
}

  replacItems() {
    this.blockItems.items1 = this.blockItems.items2;
  }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2020-05-15
@jun_dev

const bi = this.blockItems;
[ bi.items1, bi.items2 ] = [ bi.items2, bi.items1 ];

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question