[Vuejs]-<li> be moved to another <ul> by vue

0👍

If you want nested items in your list, you might have to use a recursion component, which means adding child data to your items. And calling the component inside of itself until it exhausts the list of children, by taking the data props of the child in every call.

Vue.component("listRecursion", {
  props: ['listData'],
  name: "listRecursion",
  template: `
  <div>
    <ul v-for="item in listData">
      <li>{{item.name}}</li>
      <list-recursion v-if="item.children.length" :list-data="item.children"/>
    </ul>
  </div>`
})

new Vue({
  el: "#app",
  data: {
    todos: [{
        name: "name1",
        id: "0101",
        children: [
          {
            name: "sub item 1",
            id: "0d201",
            children: []
          },
          {
            name: "sub item 2",
            id: "020g1",
            children: []
          },
          {
            name: "sub item 3",
            id: "20201",
            children: [
               {
                name: "subsub item 1",
                id: "40201",
                children: [
                  {
                  name: "subsub item 1",
                  id: "40201",
                  children: [
                    {
                    name: "subsubsub item 1",
                    id: "40201",
                    children: []
                  }]
                }]
              },
              {
                name: "subsub item 2",
                id: "50201",
                children: []
              },
            ]
          },
        ]
      },
      {
        name: "name2",
        id: "010101",
        children: []
      },
      {
        name: "name3",
        id: "010101001B",
        children: []
      },
    ]
  }
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>

<div id="app">
  <h2>Recursive list:</h2>
  <list-recursion :list-data="todos"/>
</div>

As you can see, this saves you from manually adding new levels, just add to the data to the child nodes

    0👍

    I see @procoib which solves your first case and for the li rearrange, you can do the same approach similar to ‘select’ which is shown below.

    new Vue({
      el: "#app",
      data() {
        return {
          first: [1, 2, 3, 4, 5],
          second: []
        }
      },
      methods: {
        alter: function (index, src, desc) {
          this[desc].push(this[src].splice(index, 1)[0])
        }
      }
    })
    <script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.6.11/vue.min.js"></script>
    
    <div id="app">
      <h1>First</h1>
      <ul id="firstList">
        <li v-for="(_, i) in first" v-on:click="alter(i, 'first', 'second')">{{_}}</li>
      </ul>
      
      <h1>Second</h1>
      <ul id="secondList">
        <li v-for="(_, i) in second" v-on:click="alter(i, 'second', 'first')">{{_}}</li>
      </ul>
    </div>

    If you click any number for a list, it is added to the other list.

      Leave a comment