M
M
myskypesla2018-11-06 14:55:21
Vue.js
myskypesla, 2018-11-06 14:55:21

How to dynamically load a list in Vue?

There is a code https://codesandbox.io/s/84w0wjk612
When you click on Element 1, Element 2, Element 3... a list with a drop-down menu should appear on the right and the items of this menu should be taken from the elements array, which is inside each element .
Accordingly, when element 1 is open, and after clicking on element 2, elements from the array of the current active element should be loaded into the right list.
Question: tell me the solution?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
nvdfxx, 2018-11-06
@nvdfxx

<template>
  <div class="hello">
    <ul>
      <li v-for="item in questions" :key="item.title" @click="toRightArray(item.elements)">{{ item.title }}</li>
    </ul>
    <div class="right">
      <ul>
        <li v-for="item in rightArray" :key="item">{{ item }}</li>
      </ul>
    </div>
  </div>
</template>

in data property rightArray: [],
in methods:
toRightArray(items) {
      items.forEach(el => {
        this.rightArray.push(el.title)
      })
    }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question