This article mainly shares with you vue-slicksort, which is a powerful draggable vue.js component. It can automatically scroll and lock the coordinate system. Supports smooth animation effects when dragging. Can support horizontal, vertical or grid dragging. Supports touch. Hope this article can help everyone.
DEMO
Install via npm
$ npm install vue-slicksort --save
Install via yarn
$ yarn add vue-slicksort
Introduction of components
// Using an ES6 transpiler like Babel import {ContainerMixin, ElementMixin} from 'vue-slicksort'; // Not using an ES6 transpiler var slicksort = require('vue-slicksort'); var ContainerMixin = slicksort.ContainerMixin; var ElementMixin = slicksort.ElementMixin;
Reference like this in your vue file
import Vue from 'vue'; import { ContainerMixin, ElementMixin } from 'vue-slicksort'; const SortableList = { mixins: [ContainerMixin], template: ` <ul class="list"> <slot /> </ul> `, }; const SortableItem = { mixins: [ElementMixin], props: ['item'], template: ` <li class="list-item">{{item}}</li> `, }; const ExampleVue = { name: 'Example', template: ` <p class="root"> <SortableList lockAxis="y" v-model="items"> <SortableItem v-for="(item, index) in items" :index="index" :key="index" :item="item"/> </SortableList> </p> `, components: { SortableItem, SortableList, }, data() { return { items: ['Item 1', 'Item 2', 'Item 3', 'Item 4', 'Item 5', 'Item 6', 'Item 7', 'Item 8'], }; }, }; const app = new Vue({ el: '#root', render: (h) => h(ExampleVue), });
Property | Type | Default | Description |
---|---|---|---|
Array | - | Contents of the list | |
String | y | List elements can be dragged horizontally, vertically or grid dragged. Represented by x, y, xy. | |
String | - | Used to lock the movement of elements in the coordinate system when sorting | |
String | - | helper’s custom style class | |
Number | 300 | The duration of the element movement animation | |
Number | 0 | If you need to allow dragging when the element is pressed for a period of time, you can set this attribute | |
Number | 5 | The threshold at which movement is allowed to be ignored, in pixels | |
Number | 0 | If you need to drag a certain distance before being recognized as the dragging element, you can set this attribute | |
Boolean | false | If using HandleDirective, set to true | |
Boolean | false | Whether to set the window to Scrollable container | |
Boolean | false | Whether to set the window as a scrollable container | |
Boolean | true | Whether to automatically hide ghost elements | |
Boolean | false | Whether to lock the edge of the container for the element being dragged | |
String | 50% | The offset to lock the edge of the container for the element being dragged | |
Function | - | This method will be called before dragging starts | |
Function | - | Can Select method ({node, index, collection}), used to return the calculated size of SortableHelper |
Learning to use JS drag and drop components_javascript skills
# #
The above is the detailed content of vue-slicksort a vue.js drag component. For more information, please follow other related articles on the PHP Chinese website!