Vue UI Components Documentation
The Vue DragDrop enables the user to easily drag and drop items. This guide adds the Vue DragDrop (jqxDragDrop) to an app, then shows how to set its options and handle its events.
jqwidgets-scriptsjqwidgets-scripts/jqwidgets-vue3/vue_jqxdragdrop.vue 
In a Vue 3 project (to start one, see Getting started with Vue), add the package:
npm install jqwidgets-scripts
import JqxDragDrop from 'jqwidgets-scripts/jqwidgets-vue3/vue_jqxdragdrop.vue';
import 'jqwidgets-scripts/jqwidgets/styles/jqx.base.css';
import 'jqwidgets-scripts/jqwidgets/styles/jqx.tailwind-blue-dark.css';
With <script setup>, an imported component is ready to use in the template. jqx.base.css is required; the second file is a theme, selected with the theme attribute.
The Events demo as a Single-File Component:
<template>
<div class="main-container">
<div id="draggable-parent">
<JqxDragDrop
class="draggable"
@dragStart="onDragStart($event)"
@dragEnd="onDragEnd($event)"
@dropTargetEnter="onDropTargetEnter($event)"
@dropTargetLeave="onDropTargetLeave($event)"
:restricter="restricter"
:dropTarget="'.drop-target'"
>
<div class="label">I can be dragged only inside my parent</div>
</JqxDragDrop>
<div class="drop-target">
<div class="label">I am a drop target</div>
</div>
</div>
<JqxPanel ref="myPanel" class="events" :width="260" :height="330"></JqxPanel>
</div>
</template>
<script setup>
import { onMounted, ref } from 'vue';
import JqxDragDrop from 'jqwidgets-scripts/jqwidgets-vue3/vue_jqxdragdrop.vue';
import JqxPanel from 'jqwidgets-scripts/jqwidgets-vue3/vue_jqxpanel.vue';
const myPanel = ref(null);
const restricter = ref({ left: 8, top: 8, width: 247, height: 247 });
function centerLabels() {
let labels = document.getElementsByClassName('label');
for (let i = 0; i < labels.length; i++) {
let parentHeight = labels[i].parentElement.offsetHeight;
let elementheight = labels[i].clientHeight;
let top = (parentHeight - elementheight) / 2;
labels[i].style.top = top + 'px';
}
}
function addEvent(type, position) {
let left = position.left.toString().substring(0, 2).replace(/\./g, '').replace(/\-/g, '');
let top = position.top.toString().substring(0, 2).replace(/\./g, '').replace(/\-/g, '');
myPanel.value.prepend(`<div class="row">Event: ${type}, (${left}, ${top})</div>`);
}
function onDragStart(event) {
addEvent(event.type, event.args.position);
}
function onDragEnd(event) {
addEvent(event.type, event.args.position);
}
function onDropTargetEnter(event) {
addEvent(event.type, event.args.position);
}
function onDropTargetLeave(event) {
addEvent(event.type, event.args.position);
}
onMounted(() => {
centerLabels();
});
</script>
<style>
.row {
padding: 1px;
}
.draggable > div {
border: 1px solid #bbb;
background-color: #c9ecff;
width: 100px;
height: 100px;
left: 30px;
top: 50px;
padding: 5px;
z-index: 2;
}
#draggable-parent {
background-color: #eeffee;
width: 350px;
height: 350px;
text-align: center;
border: 1px solid #eee;
float: left;
}
.main-container {
width: 650px;
z-index: 0;
}
.events > div {
float: right;
padding: 10px;
font-family: Tahoma;
font-size: 13px;
}
.label {
position: relative;
font-family: Verdana;
font-size: 11px;
color: #000;
}
.drop-target {
background-color: #fbffb5;
width: 150px;
height: 150px;
border: 1px solid #ddd;
margin-left: 190px;
margin-top: 70px;
z-index: 1;
}
</style>Options are attributes. Bind values from the script with :, for example :width="850".
Listen to an event with @ and its name. For example, dragStart: This event is triggered when the item is dragged for first time.
<script setup>
function onDragStart(event) {
console.log(event.args);
}
</script>
<template>
<JqxDragDrop @dragStart="onDragStart" />
</template>