Vue directive (Vue.js 2.x) for handling element drag & drop.
npm install draggable-vue-directive --save
You can view the live demo here: https://israelzablianov.github.io/draggable-demo
<div v-draggable>
classic draggable
</div>
.vue
file:
import { Draggable } from 'draggable-vue-directive'
...
export default {
directives: {
Draggable,
},
...
<div v-draggable="draggableValue">
<div :ref="handleId">
<img src="../assets/move.svg" alt="move">
</div>
drag and drop using handler
</div>
.vue
file:
import { Draggable } from 'draggable-vue-directive'
...
export default {
directives: {
Draggable,
},
data() {
return {
handleId: "handle-id",
draggableValue: {
handle: undefined
}
};
},
mounted() {
this.draggableValue.handle = this.$refs[this.handleId];
}
...
draggable
ValueThe object passed to the directive is called the directive’s value.
For example, in v-draggable="draggableValue"
, draggableValue
can be an object containing the folowing fields:
handle
onPositionChange
onDragEnd
onDragStart
resetInitialPos
initialPosition
stopDragging
boundingRect
boundingElement
boundingRectMargin
Type: HtmlElement | Vue
Required: false
There are two ways to use the draggable
directive, as shown in the demo above.
Type: Function
Required: false
Sometimes you need to know the element’s coordinates while it’s being dragged.
Passing a callback to draggableValue
will achieve this goal;while dragging the element, the callback will be executed with 3 params:
positionDiff
absolutePosition
(the current position; the first time the directive is added to the DOM or being initialized, the value will be undefined
, unless the element has left
and top
values)event
(the event object)import { Draggable } from 'draggable-vue-directive'
...
export default {
directives: {
Draggable,
},
data() {
return {
draggableValue: {
onPositionChange: this.onPosChanged
}
};
},
methods: {
onPosChanged: function(positionDiff, absolutePosition, event) {
console.log("left corner", absolutePosition.left);
console.log("top corner", absolutePosition.top);
}
}
...
Type: Function
Required: false
Emits only when dragging ends. Has the same functionality as onPositionChange
.
Type: Function
Required: false
Emits only when dragging starts. Has the same functionality as onPositionChange
.
Type: Boolean
Required: false
default: undefined
Returns to the initial position of the element, before it is mounted.
Type: Position
Required: false
default: undefined
Sets the absolute starting position of this element.
Will be applied when resetInitialPos
is true
.
Type: Boolean
Required: false
default: undefined
Immediately stop dragging.
Type: ClientRect
Required: false
default: undefined
Constrains dragging to within the bounds of the rectangle.
Type: HtmlElement
Required: false
default: undefined
Constrains dragging to within the bounds of the element.
Type: MarginOptions
Required: false
default: undefined
When using boundingRect
or boundingElement
, you can pass an object withtop
, left
, bottom
, and right
properties, to define a margin between the elements and the boundaries.
vue给元素添加指令 可拖动的vue指令 (draggable-vue-directive) Vue2 directive that handles drag & drop. 处理拖放的Vue2指令。 入门 (Getting Started) npm install draggable-vue-directive --save 典型用途: (Typical use:) <div v-draggab
vue自定义指令 v-directives (来源网络) 基于 vue 的自定义指令集合,包含 复制粘贴指令 v-copy 长按指令 v-longpress 输入框防抖指令 v-debounce 禁止表情及特殊字符 v-emoji 图片懒加载 v-LazyLoad 权限校验指令 v-premission 实现页面水印 v-waterMarker 拖拽指令 v-draggable v-copy 需求
一、 内置指令一览以及说明: 1、v-bind:响应并更新DOM特性;例如:v-bind:href v-bind:class v-bind:title v-bind:bb 2、v-on:用于监听DOM事件; 例如:v-on:click v-on:keyup 3、v-model:数据双向绑定;用于表单输入等;例如:<input v-model="message"> 4、v-show:条件渲染
vue项目里面创建directive文件夹然后创建index.js和drag.js两个文件,然后写如下代码 在drag.js写如下代码 /** * v-drag 弹窗拖拽 * Copyright (c) 2022 */ export default { bind(el, binding, vnode, oldVnode) { const value = binding.valu
业务逻辑,类似与navcat中的视图可视化的操作 拖动列表 生成表格并支持连线 展示效果 <el-row> <el-col :span="4"> <draggable v-model="tableData" @end="onEnd" :group="{ name: 'test', pull:
本文向大家介绍Vue组件Draggable实现拖拽功能,包括了Vue组件Draggable实现拖拽功能的使用技巧和注意事项,需要的朋友参考一下 Draggable为基于Sortable.js的vue组件,用以实现拖拽功能。 具体说明,请参考:学习链接 npm官方演示: vuedraggable特性: 支持触摸设备 支持拖拽和选择文本 支持智能滚动 支持不同列表之间的拖拽 不以jQuery为基础 和
angular 10.0+ drag and drop Demo https://mattlewis92.github.io/angular-draggable-droppable/ Table of contents About Installation Documentation Development License About Observable powered drag and dro
Categories: Interactions version added: 1.0 Description: 该组件可以让你使用鼠标拖动所有元素。 QuickNavExamples Options addClasses appendTo axis cancel connectToSortable containment cursor cursorAt delay disabled distan
UIView-draggable 是个带有拖拽功能的 UIView 类。
Draggable Tabs 是一个可拖动的 Tab 控件
Draggable Accordion 是一个可拖放的拉帘