vue-draggable-plus vs vuedraggable
Vue 3 におけるドラッグ&ドロップ実装の比較
vue-draggable-plusvuedraggable類似パッケージ:

Vue 3 におけるドラッグ&ドロップ実装の比較

vue-draggable-plusvuedraggable は、どちらも Sortable.js をラップした Vue 用ドラッグ&ドロップコンポーネントです。リストの並び替えやドラッグ操作を簡単に実装できますが、Vue のバージョン対応や TypeScript のサポート状況に違いがあります。vuedraggable は長年使われてきた標準的なライブラリで Vue 2 と 3 の両方をサポートしますが、vue-draggable-plus は Vue 3 の Composition API や TypeScript をより強く意識して設計されたモダンな代替案です。

npmのダウンロードトレンド

3 年

GitHub Starsランキング

統計詳細

パッケージ
ダウンロード数
Stars
サイズ
Issues
公開日時
ライセンス
vue-draggable-plus03,981215 kB1084ヶ月前MIT
vuedraggable020,615-2876年前MIT

vue-draggable-plus vs votedraggable: Vue 3 環境での実装比較

vue-draggable-plusvuedraggable は、どちらも Sortable.js を基盤とした Vue 用ドラッグ&ドロップライブラリです。リストの並び替え、ドラッグ操作、アニメーションを簡単に実装できますが、内部構造や Vue 3 への対応方針に明確な違いがあります。ここでは、実務での導入判断に役立つ技術的な差異を解説します。

📦 Vue バージョン対応とセットアップ

vue-draggable-plus は Vue 3 専用に設計されており、Composition API での使用を前提としています。

  • Vue 2 はサポート対象外です。
  • TypeScript の型定義が最初から含まれています。
// vue-draggable-plus: Vue 3 Composition API
import { VueDraggable } from 'vue-draggable-plus'

// setup 内で使用
<template>
  <VueDraggable v-model="items" item-key="id">
    <template #item="{ element }">
      <div>{{ element.name }}</div>
    </template>
  </VueDraggable>
</template>

vuedraggable は Vue 2 と Vue 3 の両方をサポートしますが、バージョンによって導入方法が異なります。

  • Vue 3 用は vuedraggable@next または v3 以降です。
  • Options API での使用例も多く残っています。
// votedraggable: Vue 3 Composition API
import draggable from 'vuedraggable'

// setup 内で使用
<template>
  <draggable v-model="items" item-key="id">
    <template #item="{ element }">
      <div>{{ element.name }}</div>
    </template>
  </draggable>
</template>

🛡️ TypeScript サポートと型安全性

vue-draggable-plus は TypeScript ファーストで開発されています。

  • props や events の型定義が詳細です。
  • IDE での補完が効きやすく、ミスタイプを防ぎます。
// vue-draggable-plus: 型定義が明確
import { VueDraggable } from 'vue-draggable-plus'

interface Item {
  id: number
  name: string
}

// items の型が Item[] として正しく推論される
const items = ref<Item[]>([{ id: 1, name: 'A' }])

vuedraggable は TypeScript サポートがありますが、バージョンによって精度が異なります。

  • 過去には型定義が不完全な時期がありました。
  • 追加で @types/vuedraggable が必要な場合があります。
// votedraggable: 型定義に注意
import draggable from 'vuedraggable'

interface Item {
  id: number
  name: string
}

// 型推論が効かない場合があり、手動で型を指定する必要がある
const items = ref<Item[]>([{ id: 1, name: 'A' }])

🔄 イベント処理と反応性

vue-draggable-plus は Vue 3 の反応性システムに最適化されています。

  • update:modelValue イベントを正確に発行します。
  • 配列の更新検知が確実です。
// vue-draggable-plus: イベント処理
<VueDraggable 
  v-model="items" 
  @end="onEnd"
  @update:modelValue="onChange"
>
  <!-- items -->
</VueDraggable>

<script setup>
const onEnd = (evt) => {
  console.log('Drag ended', evt)
}
</script>

vuedraggable も同様のイベントを発行しますが、Vue 3.2 以前では反応性の問題が報告されることがありました。

  • 最新の v3 以降では改善されています。
  • 旧バージョンでは change イベントなどの併用が必要でした。
// votedraggable: イベント処理
<draggable 
  v-model="items" 
  @end="onEnd"
  @input="onChange"
>
  <!-- items -->
</draggable>

<script setup>
const onEnd = (evt) => {
  console.log('Drag ended', evt)
}
</script>

🧩 スロット構文とアイテム描画

vue-draggable-plus は Vue 3 の標準的なスロット構文を採用しています。

  • #item スロットを使用します。
  • element プロパティでデータにアクセスします。
// vue-draggable-plus: スロット構文
<template #item="{ element }">
  <div class="list-item">
    {{ element.text }}
  </div>
</template>

vuedraggable も Vue 3 版では同様の構文を使用しますが、バージョン間で違いがあります。

  • Vue 2 版では v-for を内部で展開する形式でした。
  • Vue 3 版では #item に統一されています。
// votedraggable: スロット構文 (Vue 3)
<template #item="{ element }">
  <div class="list-item">
    {{ element.text }}
  </div>
</template>

📊 比較サマリー

機能vue-draggable-plusvuedraggable
Vue 3 対応✅ 専用設計✅ v3 以降で対応
Vue 2 対応❌ 非対応✅ 対応
TypeScript✅ 充実した型定義⚠️ バージョンによる
API 設計🎯 Composition API 重視🔄 Options/Composition 両方
メンテナンス🟢 活発🟡 安定 (保守モード気味)
コンポーネント名VueDraggabledraggable

💡 結論と推奨事項

vue-draggable-plus は、現代の Vue 3 開発スタックに最適化された選択です。TypeScript を使用し、Composition API で開発する新規プロジェクトでは、型安全性と反応性の確実性からこちらを推奨します。特に大規模なアプリケーションでは、型定義の充実度が維持コストに直結します。

vuedraggable は、既存の Vue 2 プロジェクトや、移行期間中のプロジェクトに適しています。実績が豊富で情報も多いため、トラブルシューティングが容易という利点があります。ただし、新規で Vue 3 のみを対象とする場合は、より現代的な vue-draggable-plus の採用を検討してください。

最終的には、プロジェクトの Vue バージョンと TypeScript の使用状況で決定します。両者とも Sortable.js を使用しているため、ドラッグ性能自体に大きな差はありません。開発体験と保守性の観点で選択するのが賢明です。

選び方: vue-draggable-plus vs vuedraggable

  • vue-draggable-plus:

    新規の Vue 3 プロジェクトで TypeScript を使用する場合は vue-draggable-plus を選択してください。Composition API との相性が良く、型定義が充実しているため、開発中のエラー検出やリファクタリングが容易になります。特に Vue 3.3 以降の機能を活用したい場合に適しています。

  • vuedraggable:

    既存の Vue 2 プロジェクトの維持や、Vue 3 への移行途中である場合は vuedraggable が安定しています。長年の実績があり、コミュニティでの情報量も豊富です。ただし、Vue 3 専用機能や高度な TypeScript 支援を必要としない場合に限定して検討してください。

vue-draggable-plus のREADME

NPM version NPM Downloads Docs & Demos
GitHub stars

vue-draggable-plus

中文文档

Drag and drop sorting module, support Vue>=v3 or Vue>=2.7

Example of use

Describe

Since the vue3 component of Sortablejs has not been updated, it has been seriously out of touch with vue3, so this project was born. This component is based on Sortablejs, so if you want to know more about Sortablejs, you can check it out Sortablejs official website

We have encapsulated a variety of usages for this, you can use components, function, or instructions, there is always one that suits you

Solve pain points

In Sortablejs official Vue components in the past, the drag-and-drop list is implemented by using the component as a direct child element of the list. When we use some component libraries, if there is no slot for the root element of the list in the component library , it is difficult for us to implement a drag list, vue-draggable-plus perfectly solves this problem, it allows you to use a drag list on any element, we can use the selector of the specified element to get the root element of the list, and then Use the root element of the list as container of Sortablejs, for details, refer to specify target container.

Install


npm install vue-draggable-plus

Usage

Component usage

<template>
    <VueDraggable ref="el" v-model="list">
      <div v-for="item in list" :key="item.id">
        {{ item.name }}
      </div>
    </VueDraggable>
</template>

<script setup lang="ts">
import { ref } from 'vue'
import { VueDraggable } from 'vue-draggable-plus'

const list = ref([
  {
    name: 'Joao',
    id: 1
  },
  {
    name: 'Jean',
    id: 2
  },
  {
    name: 'Johanna',
    id: 3
  },
  {
    name: 'Juan',
    id: 4
  }
])
</script>

Function Usage

<template>
  <div ref="el">
    <div v-for="item in list" :key="item.id">
      {{ item.name }}
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue'
import { useDraggable } from 'vue-draggable-plus'

const el = ref<HTMLElement | null>(null)
const list = ref([
  {
    name: 'Joao',
    id: 1
  },
  {
    name: 'Jean',
    id: 2
  },
  {
    name: 'Johanna',
    id: 3
  },
  {
    name: 'Juan',
    id: 4
  }
])
// The return value is an object, which contains some methods, such as start, destroy, pause, etc.
const draggable = useDraggable(el, list, {
  animation: 150,
  onStart() {
    console.log('start')
  },
  onUpdate() {
    console.log('update')
  }
})
</script>

Directive Usage

<template>
  <div
    v-draggable="[
        list,
        {
          animation: 150,
        }
      ]"
  >
    <div v-for="item in list" :key="item.id">
      {{ item.name }}
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue'
import { vDraggable } from 'vue-draggable-plus'
const list = ref([
  {
    name: 'Joao',
    id: 1
  },
  {
    name: 'Jean',
    id: 2
  },
  {
    name: 'Johanna',
    id: 3
  },
  {
    name: 'Juan',
    id: 4
  },
  {
    name: 'Yuan',
    id: 5
  }
])

function onStart() {
  console.log('start')
}

function onUpdate() {
  console.log('update')
}
</script>

Explanation

All event functions starting with on can be passed to components using v-on. For example:


<template>
  <VueDraggable v-model="list" @start="onStart" @end="onEnd"></VueDraggable>
</template>
<script lang="ts" setup>
import { ref } from "vue";
import { VueDraggable } from 'vue-draggable-plus'
import { SortableEvent } from "sortablejs";

const list = ref([
  {
    name: 'Joao',
    id: '1'
  },
  {
    name: 'Jean',
    id: '2'
  },
  {
    name: 'Johanna',
    id: '3'
  },
  {
    name: 'Juan',
    id: '4'
  }
])

function onStart(event: SortableEvent) {
  console.log('start drag')
}

function onEnd(event: SortableEvent) {
  console.log('end drag')
}
</script>

For information on using Hooks and directives, please refer to the documentation.

Options

Options inherits all configuration items from Sortablejs. For details, please see the Sortablejs official documentation.

Types

type Easing =
  | 'steps(int, start | end)'
  | 'cubic-bezier(n, n, n, n)'
  | 'linear'
  | 'ease'
  | 'ease-in'
  | 'ease-out'
  | 'ease-in-out'
  | 'step-start'
  | 'step-end'
  | 'initial'
  | 'inherit'

type PullResult = ReadonlyArray<string> | boolean | 'clone';
type PutResult = ReadonlyArray<string> | boolean;

interface GroupOptions {
  /**
   * Group name.
   */
  name: string;
  /**
   * The ability to move from the list. Clone - copy the item instead of moving it.
   */
  pull?: PullResult | ((to: Sortable, from: Sortable, dragEl: HTMLElement, event: SortableEvent) => PullResult) | undefined;
  /**
   * Whether elements can be added from other lists, or an array of group names from which elements can be obtained.
   */
  put?: PutResult | ((to: Sortable, from: Sortable, dragEl: HTMLElement, event: SortableEvent) => PutResult) | undefined;
  /**
   * After moving to another list, the cloned element is restored to its initial position.
   */
  revertClone?: boolean | undefined;
}

type Group = string | GroupOptions | undefined;

type ScrollFn = ((
        this: Sortable,
        offsetX: number,
        offsetY: number,
        originalEvent: Event,
        touchEvt: TouchEvent,
        hoverTargetEl: HTMLElement,
    ) => 'continue' | void) | undefined;

API

ParameterDescriptionTypeDefault
animationShow animation while draggingNumber0
chosenClassCSS class name for chosen itemString'sortable-chosen'
delayDelay in milliseconds before drag startsNumber0
delayOnTouchOnlyDelay on touch eventBooleanfalse
directionDragging direction, 'vertical' or 'horizontal' (default auto detect)String-
disabledDisable draggingBooleanfalse
dragClassCSS class name for dragged itemString'sortable-drag'
draggableSelector for draggable items within elementString-
emptyInsertThresholdDistance (in pixels) from empty sortable items where dragging element should be inserted. Set to 0 to disable this feature.Number5
easingAnimation easingEasing-
fallbackClassCSS class name for cloned DOM elements when using forceFallbackStringsortable-fallback
fallbackOnBodyAppend cloned DOM element to body elementBooleanfalse
fallbackTolerancePixels mouse must move before drag start when using forceFallbackNumber0
filterSelector for items that should not be draggableString-
forceFallbackIgnore HTML5 drag and drop behavior and force fallbackBooleanfalse
ghostClassCSS class name for drop placeholderString'sortable-ghost'
groupGroup items to drag between sortable lists. Both lists must have the same group value. Also define whether lists can be dragged out of, cloned, or receive elements from other lists. See TypeScript type definition above for details.Group-
handleSelector for handle to initiate drag. If not set, the target element's children are usedString-
invertSwapAlways use inverted swap zone if set to trueBooleanfalse
invertedSwapThresholdInverted swap zone threshold, defaults to swapThreshold valueNumber-
preventOnFilterCall event.preventDefault() on filter eventBooleantrue
removeCloneOnHideRemove instead of hiding cloned element when not displayedBooleantrue
sortAllow list items to be sorted within containerBooleantrue
swapThresholdSwap zone thresholdNumber1
touchStartThresholdPixels before cancelling delay touch eventNumber1
setDataPass a function where the first argument is of type DataTransfer and the second argument is of type HTMLElementFunction-
scrollEnable scrollingBooleanHTMLElement
scrollFnCustom scroll functionScrollFn-
scrollSensitivityThe distance in pixels the mouse must be to the edge to start scrollingNumber-
scrollSpeedThe scrolling speed in ms/pxnumber-
bubbleScrollEnables automatic scrolling for all parent elements to make it easier to move itemsBooleantrue
onChooseTriggered when an item is selected((event: SortableEvent) => void)-
onUnchooseTriggered when an item is deselected((event: SortableEvent) => void)-
onStartTriggered when an item is picked up for drag and drop((event: SortableEvent) => void)-
onEndTriggered when an item is no longer being dragged((event: SortableEvent) => void)-
onAddTriggered when an item is moved from one list to another((event: SortableEvent) => void)-
onUpdateTriggered when the order of the items is updated((event: SortableEvent) => void)-
onSortTriggered whenever any changes are made to the list((event: SortableEvent) => void)-
onRemoveTriggered when an item is removed from the list and moved to another((event: SortableEvent) => void)-
onFilterTriggered when trying to drag a filtered item((event: SortableEvent) => void)-
onMoveTriggered while an item is being dragged((event: MoveEvent,originalEvent: Event) => void)-
onCloneTriggered when an item is cloned((event: SortableEvent) => void)-
onChangeTriggered when an item is dragged and changes position((event: SortableEvent) => void)-