vue.js 拖拽排序

vue-smooth-dnd (vue-smooth-dnd)

A fast and lightweight drag&drop, sortable library for Vue.js with many configuration options covering many d&d scenarios.

用于Vue.js的快速,轻巧的拖放式可排序库,具有许多配置选项,涵盖了许多d&d场景。

This library consists wrapper Vue.js components over smooth-dnd library.

该库由smooth-dnd库组成的包装Vue.js组件。

Show, don't tell !

显示,不告诉!

View demo 查看演示 Download Source 下载源

安装 (Installation)

npm i vue-smooth-dnd

用法 (Usage)

Vue (Vue)

<template><div><div class="simple-page"><Container @drop="onDrop">            <Draggable v-for="item in items" :key="item.id"><div class="draggable-item">{{item.data}}</div></Draggable></Container></div></div>
</template><script>
import { Container, Draggable } from "vue-smooth-dnd";
import { applyDrag, generateItems } from "./utils";
export default {name: "Simple",components: { Container, Draggable },data: function() {return {items: generateItems(50, i => ({ id: i, data: "Draggable " + i }))};},methods: {onDrop: function(dropResult) {this.items = applyDrag(this.items, dropResult);}}
};
</script>

API (API)

容器 (Container)

Component that contains the draggable elements or components. Each of its children should be wrapped by Draggable component

包含可拖动元素或组件的组件。 它的每个子级都应由Draggable组件包装

物产 (Properties)

Property Type Default Description
:orientation string vertical Orientation of the container. Can be horizontal or vertical.
:behaviour string move Property to describe weather the dragging item will be moved or copied to target container. Can be move or copy.
:group-name string undefined Draggables can be moved between the containers having the same group names. If not set container will not accept drags from outside. This behaviour can be overriden by shouldAcceptDrop function. See below.
:lock-axis string undefined Locks the movement axis of the dragging. Possible values are x, y or undefined.
:drag-handle-selector string undefined Css selector to test for enabling dragging. If not given item can be grabbed from anywhere in its boundaries.
:non-drag-area-selector string undefined Css selector to prevent dragging. Can be useful when you have form elements or selectable text somewhere inside your draggable item. It has a precedence over dragHandleSelector.
:drag-begin-delay number 0 (200 for touch devices) Time in milisecond. Delay to start dragging after item is pressed. Moving cursor before the delay more than 5px will cancel dragging.
:animation-duration number 250 Animation duration in milisecond. To be consistent this animation duration will be applied to both drop and reorder animations.
:auto-scroll-enabled boolean true First scrollable parent will scroll automatically if dragging item is close to boundaries.
:drag-class string undefined Class to be added to the ghost item being dragged. The class will be added after it's added to the DOM so any transition in the class will be applied as intended.
:drop-class string undefined Class to be added to the ghost item just before the drop animation begins.
@drag-start function undefined See descriptions below
@drop function undefined See descriptions below
:get-child-payload function undefined See descriptions below
:should-animate-drop function undefined See descriptions below
:should-accept-drop function undefined See descriptions below
@drag-enter function undefined See descriptions below
@drag-leave function undefined See descriptions below
属性 类型 默认 描述
:方向 vertical 容器的方向。 可以是水平垂直的
:行为 move 描述天气的属性,拖动项将被移动或复制到目标容器。 可以移动复制
:团队名字 undefined 可以在具有相同组名的容器之间移动可拖动对象。 如果未设置,则容器将不接受来自外部的拖动。 可以通过shouldAcceptDrop函数覆盖此行为。 见下文。
:锁轴 undefined 锁定拖动的移动轴。 可能的值为xyundefined
:拖动句柄选择器 undefined CSS选择器进行测试以启用拖动。 如果没有提供,则可以从其边界内的任何位置抓取物品。
:非拖动区域选择器 undefined CSS选择器可防止拖动。 当您在可拖动项内的某处具有表单元素或可选文本时,此选项很有用。 它的优先级高于dragHandleSelector
:拖曳开始延迟 0 (触摸设备为200 ) 时间以毫秒为单位。 按下项目后开始拖动的延迟时间。 在延迟超过5px之前移动光标将取消拖动。
:动画持续时间 250 动画持续时间(以毫秒为单位)。 为了保持一致,此动画持续时间将同时应用于拖放动画和重新排序动画。
:启用自动滚动 布尔值 true 如果拖动项靠近边界,则第一个可滚动父级将自动滚动。
:拖动类 undefined 要添加到要拖动的幻影项的类。 该类将在添加到DOM之后添加,因此该类中的任何过渡都将按预期应用。
:下降级 undefined 在放下动画开始之前要添加到ghost项目的类。
@ drag-start 功能 undefined 请参阅下面的说明
@下降 功能 undefined 请参阅下面的说明
:get-child-payload 功能 undefined 请参阅下面的说明
:应该动画放 功能 undefined 请参阅下面的说明
:应该接受 功能 undefined 请参阅下面的说明
@ drag-enter 功能 undefined 请参阅下面的说明
@ drag-leave 功能 undefined 请参阅下面的说明


拖动开始 (drag-start)

Event to be emitted only by the container which drag starts from.

仅由拖动开始的容器发出的事件。

@drag-start="onDragStart($event)"onDragStart: function({index, payload}) {...
}

参量 (Parameters)

  • event : object

    事件object

    • index : indexnumber : index of the child itemnumber :子项的索引
    • payload : 有效负载object : the payload object that is returned by get-child-payload function. It will be undefined in case get-child-payload is not set.object :由get-child-payload函数返回的有效负载对象。 如果未设置get-child-payload,它将是未定义的。

下降 (drop)

The event to be emitted by any relevant container when drop is over. (After drop animation ends). Source container and any container that could accept drop is considered relevant.

放置结束时,任何相关容器将发出的事件。 (放下动画结束后)。 源容器和任何可以接受降落的容器都被认为是相关的。

@drop="onDrop($event)"onDrop: function(dropResult) {const { removedIndex, addedIndex, payload, element } = dropResult;...
}

参量 (Parameters)

  • dropResult : object

    dropResultobject

    • removedIndex : removeIndexnumber : index of the removed children. Will be number :移除的孩子的索引。 如果未删除任何项目,则为null if no item is removed.null
    • addedIndex : addIndexnumber : index to add droppped item. Will be number :添加删除项目的索引。 如果未添加任何项目,则为null if no item is added.null
    • payload : payloadobject : the payload object retrieved by calling object :通过调用get-child-payload function.get-child-payload函数检索的有效载荷对象。
    • element : elementDOMElement : the DOM element that is movedDOMElement :移动的DOM元素

获得孩子的有效载荷 (get-child-payload)

The function to be called to get the payload object to be passed onDrop function.

要获取要通过onDrop函数传递的有效负载对象的函数。

:get-child-payload="getChildPayload"getChildPayload: function(index) {return {...}
}

参量 (Parameters)

  • index : number : index of the child item

    indexnumber :子项的索引

退货 (Returns)

  • payload : object

    有效负载object

应该动画掉落 (should-animate-drop)

The function to be called by the target container to which the dragged item will be droppped. Sometimes dragged item's dimensions are not suitable with the target container and dropping animation can be wierd. So it can be disabled by returning false. If not set drop animations are enabled.

将被拖放的项目放置到的目标容器所调用的函数。 有时,被拖动项目的尺寸不适合目标容器,并且放下动画可能会很麻烦。 因此可以通过返回false禁用它。 如果未设置,则启用放下动画。

:should-animate-drop="shouldAnimateDrop"shouldAnimateDrop: function(sourceContainerOptions, payload) {return false;
}

参量 (Parameters)

  • sourceContainerOptions : object : options of the source container. (parent container of the dragged item)

    sourceContainerOptionsobject :源容器的选项。 (被拖动项的父容器)

  • payload : object : the payload object retrieved by calling get-child-payload function.

    payloadobject :通过调用get-child-payload函数检索的有效载荷对象。

退货 (Returns)

  • boolean : true / false

    布尔值对/错

应该接受 (should-accept-drop)

The function to be called by all containers before drag starts to determine the containers to which the drop is possible. Setting this function will override the group-name property and only the return value of this function will be taken into account.

开始拖动之前,所有容器都将调用该函数,以确定可以将其拖放到的容器。 设置此函数将覆盖group-name属性,并且仅考虑该函数的返回值。

:should-accept-drop="shouldAcceptDrop"shouldAcceptDrop: function(sourceContainerOptions, payload) {return true;
}

参量 (Parameters)

  • sourceContainerOptions : object : options of the source container. (parent container of the dragged item)

    sourceContainerOptionsobject :源容器的选项。 (被拖动项的父容器)

  • payload : object : the payload object retrieved by calling get-child-payload function.

    payloadobject :通过调用get-child-payload函数检索的有效载荷对象。

退货 (Returns)

  • boolean : true / false

    布尔值对/错

拖动输入 (drag-enter)

The event to be emitted by the relevant container whenever a dragged item enters its boundaries while dragging.

每当拖动的项目进入其边界时,相关容器将发出的事件。

@drag-enter="onDragEnter()"onDragEnter: function() {...
}

拖曳离开 (drag-leave)

The event to be emitted by the relevant container whenever a dragged item leaves its boundaries while dragging.

每当拖动的项目离开其边界时,相关容器将发出的事件。

@drag-leave="onDragLeave()"onDragLeave: function() {...
}

可拖动 (Draggable)

Wrapper component for Container's children. Every child element should be wrapped with Draggable component.

容器子项的包装器组件。 每个子元素都应使用Draggable组件包装。

翻译自: https://vuejsexamples.com/a-fast-and-lightweight-drag-drop-sortable-library-for-vue-js/

vue.js 拖拽排序

vue.js 拖拽排序_快速轻巧的Vue.js拖放可排序库相关推荐

  1. js拖拽360桌面悬浮球代码

    js拖拽360桌面悬浮球代码 原生js制作简单好用的360桌面悬浮球,可拖拽到浏览器边缘,自动贴边,自动适应屏幕效果. 演示地址 下载地址

  2. 【组件】前端js拖拽插件 VUE

    [组件]前端js拖拽插件 VUE Vue Draggable - Vue 拖拽组件王者 Vue drag resize - 轻量级,无依赖,可缩放 Vue smooth dnd - 简单动效,上下拖拽 ...

  3. html列表拖拽排序插件,JS拖拽排序插件Sortable.js用法实例分析

    本文实例讲述了JS拖拽排序插件Sortable.js用法.分享给大家供大家参考,具体如下: 最近由于项目功能设计的原因,需要对table中的行实现拖拽排序功能,找来找去发现Sortable.js能很好 ...

  4. sortable 拖拽时互换目标的位置_双端通用型JS拖拽插件的封装与应用

    最近工作中遇到一个需求,需要将一个元素从某位置拖动到另一固定位置后执行某一交互行为,具体效果如下: 这个看似简单的需求,然而实现起来却并不那么顺利.我首先想到的是如何通过哪个现有的插件来快速解决这个问 ...

  5. vue 实现文本的拖拽_基于Vue实现拖拽功能

    本文实例为大家分享了Vue实现拖拽功能的具体代码,供大家参考,具体内容如下 效果图: HTML代码: 位置 x:{{val.x}} y:{{val.y}} //注意这里要通过指令绑定函数将当前元素的位 ...

  6. vue可视化拖拽生成工具_一款可拖拽的WEB表单设计布局器-(echarts-vue-jquery-可视化图表)...

    背景 现在越来越多的业务要求运营可以自由定制化页面,此过程最大的好处就是前端研发不用介入就能完成页面的定制化,大大提升了产品的灵活性,减轻前端工程师的工作量 还有一些场景:用户可以自由定制图表工具,通 ...

  7. html 树形图可拖拽,HTML5拖拽API实现vue树形拖拽组件

    因业务场景需要一个可拖拽修改节点位置的树形组件,因此动手撸了一个,乘此机会摸了一把html5原生拖拽.近期有时间将核心部分代码抽出,简单说下实现方式. 1.树形结构-组件递归使用 树形结构非常简单,t ...

  8. js拖拽库——Sortable.js

    Sortable.js是一款优秀的js拖拽库,支持ie9及以上版本ie浏览器和现代浏览器,也可以运行在移动触摸设备中.不依赖jQuery.支持 Meteor.AngularJS.React.Vue.K ...

  9. 拖拽功能 php,基于Vue实现拖拽功能

    这篇文章主要为大家详细介绍了Vue实现拖拽功能,拖动方块进行移动,具有一定的参考价值,感兴趣的小伙伴们可以参考一下 本文实例为大家分享了Vue实现拖拽功能的具体代码,供大家参考,具体内容如下 效果图: ...

最新文章

  1. python开发工资多少-三年 python web 开发,在深圳工资大概时多少?
  2. 实训23 2018.4.27
  3. 固态硬盘量产工具_机械硬盘Q1出货量大降,电脑硬盘榜单出炉
  4. Openfire开发配置,Openfire源码配置,OpenFire二次开发配置
  5. nginx配置openssl证书
  6. python计算手机销量年增长率_Python对商店数据进行lstm和xgboost销售量时间序列建模预测分析...
  7. 机器学习中的训练集、验证集、测试集;交叉验证方法
  8. JPM Coin— 货币非国家化的开端 | TokenInsight
  9. RFID在图书馆系统管理中的有哪些应用优势?
  10. 打造铜墙铁壁 DDoS攻击全面解析
  11. 做一个迷你播放器放在桌面
  12. uCLinux系统分析
  13. Spring Bean到底是什么?有什么用?
  14. Win10下安装wsl2
  15. oracle超大表建索引,Oracle 大表创建索引
  16. [ CTF ]MISC encode
  17. Basics(基础)
  18. 大包改小包_旧包改造,改成可以放在口袋里的小包包
  19. 计算机教师招聘板书设计,教师招聘或资格证面试试讲—试讲提分技巧之板书设计...
  20. 学习笔记第五十节:原根相关与二次剩余

热门文章

  1. Android 省电模式 降频吗,开启省电模式会降频吗
  2. 跨越专业翻译的语言之墙:百度翻译的技术攀登
  3. 使用matlab建立个人简历,HTML 使用表格制作简单的个人简历
  4. 今日头条 巨量引擎 marketing api
  5. python爬取微信好友头像_使用python itchat包爬取微信好友头像形成矩形头像集的方法...
  6. 二战计算机技术,重庆大学超强二战跨考计算机技术专业经验,学习方法
  7. Notepad++ 插件 JsonViewer V1.40 64位32位
  8. ijk基于exo_基于 ExoPlayer 的 ExoVideoView
  9. 第二章 Java流程控制 ① 笔记
  10. java 首字母大写方法