1.5.0 • Published 6 years ago

vue-drag-2.0 v1.5.0

Weekly downloads
2
License
ISC
Repository
github
Last release
6 years ago

Vue-dragable

适用于vue2.0

NPM

github: https://github.com/ppya0812/vue-dragable

使用方法

NPM安装

npm install vue-drag
	

页面调用

<template>
	<div v-sortable="{onUpdate: onUpdate, preventOnFilter: false}" class="drag-list">
		<div v-for="v in list" :key="v" class="drag-item">
		</div>
	</div>
</template>
<script>
import Vue from 'vue'
import Drag from '@/wm-kit/packages/drag/src/vueDrag'

Vue.use(Drag)
export default {
	data() {
		return {
	    list: ['Foo', 'Bar', 'Baz']
		}
  },
  methods: {
    onUpdate: function (event) {
      this.list.splice(event.newIndex, 0, this.list.splice(event.oldIndex, 1)[0])
    }
  }
}
</script>

使用示例

<template>
	<div v-sortable="{onUpdate: onUpdate, preventOnFilter: false}" class="drag-list">
		<div v-for="v in list" :key="v" class="drag-item">
			{{v}}
		</div>
	</div>
</template>

<script>
import Vue from 'vue'
import Drag from '@/wm-kit/packages/drag/src/vueDrag'

Vue.use(Drag)
export default {
	data() {
		return {
	    list: ['Foo', 'Bar', 'Baz']
		}
  },
  methods: {
    onUpdate: function (event) {
      this.list.splice(event.newIndex, 0, this.list.splice(event.oldIndex, 1)[0])
    }
  }
}

</script>

<style>
	.drag-list {
		border: 1px solid #f6f6f6;
		width: 50%;
	}
	.drag-item {
		border-top: 1px solid #f6f6f6;
		height: 30px;
		line-height: 30px;
		background: #ccc;
	}
	.sortable-chosen {
		background: #f5f5f5;
	}

</style>

API 属性介绍 Attributes:

nametypedefaultdescription
groupString'name'or { name: "...", pull: true, false, clone, put: true, false, array }
delaynumber0延迟时间 time in milliseconds to define when the sorting should start
sortBooleantrue是否排序sorting inside list
disabledBooleanfalsedrag功能失效Disables the sortable if set to trueshould start
animationBoolean150ms, animation speed moving items when sorting, 0 — without animation
preventOnFilterBooleantrue不阻止非filter区域的默认事件 Call event.preventDefault() when triggered filter
storeObjectnull@see Store
handleString'.my-handle'Drag handle selector within list itemsfilter
filterString".ignore-elements"过滤不拖拽的元素 Selectors that do not lead to dragging (String or Function) should filter
draggableString".item"Specifies which items inside the element should be draggable
ghostClassString"sortable-ghost"// Class name for the drop placeholder
chosenClassString"sortable-chosen"// Class name for the chosen item
dragClassString"sortable-drag"// Class name for the dragging item
dataIdAttrString'data-id'
forceFallbackStringfalse// ignore the HTML5 DnD behaviour and force the fallback to kick in
fallbackClassString"sortable-fallback"// Class name for the cloned DOM Element when using forceFallback
fallbackOnBodyStringfalse// Appends the cloned DOM Element into the Document's Body
fallbackToleranceString0// Specify in pixels how far the mouse should move before it's considered as a drag.
scrollStringtrue// or HTMLElement
scrollFnStringfunction(offsetX, offsetY, originalEvent) { ... }// if you have custom scrollbar scrollFn may be used for autoscrolling
scrollSensitivityString30// px, how near the mouse must be to an edge to start scrolling.
scrollSpeedString10// px

函数api

1.setData

function (/** DataTransfer */dataTransfer, /** HTMLElement*/dragEl) {
	dataTransfer.setData('Text', dragEl.textContent); // `dataTransfer` object of HTML5 DragEvent
}

2. onChoose:

function (/**Event*/evt) {
	evt.oldIndex;  // element index within parent
}

3. onStart:

// Element dragging started

function (/**Event*/evt) {
	evt.oldIndex;  // element index within parent
}

4. onEnd:

// Element dragging ended
function (/**Event*/evt) {
	evt.oldIndex;  // element's old index within parent
	evt.newIndex;  // element's new index within parent
},

5. onAdd:

// Element is dropped into the list from another list
function (/**Event*/evt) {
	var itemEl = evt.item;  // dragged HTMLElement
	evt.from;  // previous list
	// + indexes from onEnd
},

6. onUpdate:

// Changed sorting within list
function (/**Event*/evt) {
	var itemEl = evt.item;  // dragged HTMLElement
	// + indexes from onEnd
},

7. onSort:

// Called by any change to the list (add / update / remove)
function (/**Event*/evt) {
	// same properties as onUpdate
},

8. onRemove:

// Element is removed from the list into another list
function (/**Event*/evt) {
	// same properties as onUpdate
},

9. onFilter:

// Attempt to drag a filtered element
function (/**Event*/evt) {
	var itemEl = evt.item;  // HTMLElement receiving the `mousedown|tapstart` event.
},

10. onMove:

// Event when you move an item in the list or between lists
function (/**Event*/evt, /**Event*/originalEvent) {
	// Example: http://jsbin.com/tuyafe/1/edit?js,output
	evt.dragged; // dragged HTMLElement
	evt.draggedRect; // TextRectangle {left, top, right и bottom}
	evt.related; // HTMLElement on which have guided
	evt.relatedRect; // TextRectangle
	originalEvent.clientY; // mouse position
	// return false; — for cancel
},

11. onClone:

// Called when creating a clone of element
function (/**Event*/evt) {
	var origEl = evt.item;
	var cloneEl = evt.clone;
}
1.5.0

6 years ago

1.4.0

6 years ago

1.2.0

7 years ago

1.1.0

7 years ago

1.0.6

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago