Help us understand the problem. What is going on with this article?

【Vue.Draggable】二列間の移動

ドラッグ&ドロップが実装できるライブラリを使ってみたので、メモです。

SortableJS/Vue.Draggable

前回の記事
この記事の目標
  • 項目ドラッグで、リスト間の列移動ができるところまで

目次

  1. 全体
  2. ポイント
  3. 参考
環境
  • Vue.js 2.6.11

  • Vue.Draggable 2.23.2

1.全体

<template>
  <div class="draggable">
    <div class="d-flex">
      <!-- ポケモン -->
      <div class="col-4">
        <h6 class="font-weight-bold">ポケモン</h6>
        <draggable group="monsters" tag="ul" class="list-group" :list="pokemons">
          <li class="list-group-item" v-for="pokemon in pokemons" :key="pokemon.no">
            {{ pokemon.name }}
          </li>
        </draggable>
      </div>
      <!-- デジモン -->
      <div class="col-4">
        <h6 class="font-weight-bold">デジモン</h6>
        <draggable group="monsters" tag="ul" class="list-group" :list="digimons">
          <li class="list-group-item" v-for="digimon in digimons" :key="digimon.no">
            {{ digimon.name }}
          </li>
        </draggable>
      </div>
    </div>
  </div>
</template>

<script>
import draggable from 'vuedraggable'

export default {
  components: {
    draggable
  },
  data () {
    return {
      pokemons: [
        { no: '001', name: 'フシギダネ' },
        { no: '004', name: 'ヒトカゲ' },
        { no: '007', name: 'ゼニガメ' },
        { no: '025', name: 'ピカチュウ' }
      ],
      digimons: [
        { no: '111', name: 'アグモン' },
        { no: '222', name: 'カブテリモン' },
        { no: '333', name: 'エンジェウーモン' },
        { no: '444', name: 'セントガルゴモン' }
      ]
    }
  }
}
</script>

<style scoped>
li {
  cursor: pointer;
}
</style>

05f09e0e9676693f4c8ccd6c43e72b29.gif

  • ポケモンリストとデジモンリストについて、ドラッグで列間移動できる

2.ポイント

  • <draggable>に、group="任意のグループ名" を付与する

  • 同じ名前のグループ同士は、列間の移動ができるようになる

4行目〜
<!-- ポケモン -->
<div class="col-4">
  <h6 class="font-weight-bold">ポケモン</h6>
  <draggable group="monsters" tag="ul" class="list-group" :list="pokemons">
13行目〜
<!-- デジモン -->
<div class="col-4">
  <h6 class="font-weight-bold">デジモン</h6>
  <draggable group="monsters" tag="ul" class="list-group" :list="digimons">

↑ ポケモンとデジモンのリストそれぞれに、monstersグループを付与しています

3.参考

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした