Gathering detailed insights and metrics for vue-draggable-next
Gathering detailed insights and metrics for vue-draggable-next
Gathering detailed insights and metrics for vue-draggable-next
Gathering detailed insights and metrics for vue-draggable-next
npm install vue-draggable-next
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
509 Stars
53 Commits
46 Forks
7 Watching
6 Branches
3 Contributors
Updated on 08 Nov 2024
Minified
Minified + Gzipped
TypeScript (65.27%)
JavaScript (34.73%)
Cumulative downloads
Total Downloads
Last day
-4.9%
12,859
Compared to previous day
Last week
5.5%
65,935
Compared to previous week
Last month
12.5%
269,024
Compared to previous month
Last year
120.9%
2,444,227
Compared to previous year
2
33
Vue 3 drag-and-drop component based on Sortable.js
Demo.
npm install vue-draggable-next
//or
yarn add vue-draggable-next
1<template> 2 <div class="flex m-10"> 3 <draggable class="dragArea list-group w-full" :list="list" @change="log"> 4 <div 5 class="list-group-item bg-gray-300 m-1 p-3 rounded-md text-center" 6 v-for="element in list" 7 :key="element.name" 8 > 9 {{ element.name }} 10 </div> 11 </draggable> 12 </div> 13</template> 14<script> 15 import { defineComponent } from 'vue' 16 import { VueDraggableNext } from 'vue-draggable-next' 17 export default defineComponent({ 18 components: { 19 draggable: VueDraggableNext, 20 }, 21 data() { 22 return { 23 enabled: true, 24 list: [ 25 { name: 'John', id: 1 }, 26 { name: 'Joao', id: 2 }, 27 { name: 'Jean', id: 3 }, 28 { name: 'Gerard', id: 4 }, 29 ], 30 dragging: false, 31 } 32 }, 33 methods: { 34 log(event) { 35 console.log(event) 36 }, 37 }, 38 }) 39</script>
transition-group
:1<draggable v-model="myArray"> 2 <transition-group> 3 <div v-for="element in myArray" :key="element.id">{{element.name}}</div> 4 </transition-group> 5</draggable>
1<draggable v-model="myList"></draggable>
1computed: { 2 myList: { 3 get() { 4 return this.$store.state.elements 5 }, 6 set(value) { 7 this.$store.dispatch('updateElements', value) 8 } 9 } 10}
Type: Array
Required: false
Default: null
Input array to draggable component. Typically same array as referenced by inner element v-for directive.
This is the preferred way to use Vue.draggable as it is compatible with Vuex.
It should not be used directly but only though the v-model
directive:
1<draggable v-model="myArray"></draggable>
Type: Array
Required: false
Default: null
Alternative to the value
prop, list is an array to be synchronized with drag-and-drop.
The main difference is that list
prop is updated by draggable component using splice method, whereas value
is immutable.
Do not use in conjunction with value prop.
New in version 2.19
Sortable options can be set directly as vue.draggable props since version 2.19.
This means that all sortable option are valid sortable props with the notable exception of all the method starting by "on" as draggable component expose the same API via events.
kebab-case propery are supported: for example ghost-class
props will be converted to ghostClass
sortable option.
Example setting handle, sortable and a group option:
1<draggable 2 v-model="list" 3 handle=".handle" 4 :group="{ name: 'people', pull: 'clone', put: false }" 5 ghost-class="ghost" 6 :sort="false" 7 @change="log" 8 > 9 <!-- --> 10</draggable>
Type: String
Default: 'div'
HTML node type of the element that draggable component create as outer element.
Type: String
Default: 'null'
It is also possible to pass the name of vue component as element. In this case, draggable attribute will be passed to the create component.
Type: Function
Required: false
Default: null
if you need to set props or attrs to the created component.
Type: Function
Required: false
Default: (original) => { return original;}
Function called on the source component to clone element when clone option is true. The unique argument is the viewModel element to be cloned and the returned value is its cloned version.
By default vue-draggable-next reuses the viewModel element, so you have to use this hook if you want to clone or deep clone it.
Type: Function
Required: false
Default: null
If not null this function will be called in a similar way as Sortable onMove callback. Returning false will cancel the drag operation.
1function onMoveCallback(evt, originalEvent){ 2 ... 3 // return false; — for cancel 4}
evt object has same property as Sortable onMove event, and 3 additional properties:
draggedContext
: context linked to dragged element
index
: dragged element indexelement
: dragged element underlying view model elementfutureIndex
: potential index of the dragged element if the drop operation is acceptedrelatedContext
: context linked to current drag operation
index
: target element indexelement
: target element view model elementlist
: target listcomponent
: target VueComponentHTML:
1<draggable :list="list" :move="checkMove">
javascript:
1checkMove: function(evt){ 2 return (evt.draggedContext.element.name!=='apple'); 3}
Support for Sortable events:
start
, add
, remove
, update
, end
, choose
, unchoose
, sort
, filter
, clone
Events are called whenever onStart, onAdd, onRemove, onUpdate, onEnd, onChoose, onUnchoose, onSort, onClone are fired by Sortable.js with the same argument.
See here for reference
HTML:
1<draggable :list="list" @end="onEnd">
change event
change
event is triggered when list prop is not null and the corresponding array is altered due to drag-and-drop operation.
This event is called with one argument containing one of the following properties:
added
: contains information of an element added to the array
newIndex
: the index of the added elementelement
: the added elementremoved
: contains information of an element removed from to the array
oldIndex
: the index of the element before removeelement
: the removed elementmoved
: contains information of an element moved within the array
newIndex
: the current index of the moved elementoldIndex
: the old index of the moved elementelement
: the moved elementThis project is heavily inspired by the following awesome vue 2 projects.
Thanks!
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 2/26 approved changesets -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
security policy file not detected
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
70 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-11-25
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More