Drag and drop in Vue File manager component
20 Dec 20245 minutes to read
The File manager allows files or folders to be moved from one folder to another by using the allowDragAndDrop property. It also supports uploading files by dragging them from Windows Explorer to the File manager control. You can enable or disable this feature by using the allowDragAndDrop property.
The events triggered during drag and drop operations are:
- fileDragStart - Triggered when dragging a file or folder begins.
- fileDragging - Triggered while a file or folder is being dragged.
- fileDragStop - Triggered when a file or folder is about to be dropped on the target..
- fileDropped - Triggered when a file or folder is dropped.
<template>
<div id="app">
<ejs-filemanager id="file-manager" :allowDragAndDrop="allowDragAndDrop" :fileDragStart="onFileDragStart" :fileDragStop="onFileDragStop" :fileDragging="onFileDragging" :fileDropped="onFileDropped" :ajaxSettings="ajaxSettings">
</ejs-filemanager>
</div>
</template>
<script setup>
import { provide } from "vue";
import { FileManagerComponent as EjsFilemanager, DetailsView, NavigationPane, Toolbar } from "@syncfusion/ej2-vue-filemanager";
const ajaxSettings =
{
url: "https://ej2-aspcore-service.azurewebsites.net/api/FileManager/FileOperations",
getImageUrl: "https://ej2-aspcore-service.azurewebsites.net/api/FileManager/GetImage",
uploadUrl: "https://ej2-aspcore-service.azurewebsites.net/api/FileManager/Upload",
downloadUrl: "https://ej2-aspcore-service.azurewebsites.net/api/FileManager/Download"
};
const allowDragAndDrop = true;
const onFileDragStart = function(){
console.log("File Drag Start");
};
const onFileDragStop = function(){
console.log("File Drag Stop");
};
const onFileDragging = function(){
console.log("File Dragging");
};
const onFileDropped = function(){
console.log("File Dropped");
};
provide('filemanager', [DetailsView, NavigationPane, Toolbar]);
</script>
<style>
@import "../node_modules/@syncfusion/ej2-base/styles/material.css";
@import "../node_modules/@syncfusion/ej2-icons/styles/material.css";
@import "../node_modules/@syncfusion/ej2-inputs/styles/material.css";
@import "../node_modules/@syncfusion/ej2-popups/styles/material.css";
@import "../node_modules/@syncfusion/ej2-buttons/styles/material.css";
@import "../node_modules/@syncfusion/ej2-splitbuttons/styles/material.css";
@import "../node_modules/@syncfusion/ej2-navigations/styles/material.css";
@import "../node_modules/@syncfusion/ej2-layouts/styles/material.css";
@import "../node_modules/@syncfusion/ej2-grids/styles/material.css";
@import "../node_modules/@syncfusion/ej2-vue-filemanager/styles/material.css";
</style>
<template>
<div id="app">
<ejs-filemanager id="file-manager" :allowDragAndDrop="allowDragAndDrop" :fileDragStart="onFileDragStart" :fileDragStop="onFileDragStop" :fileDragging="onFileDragging" :fileDropped="onFileDropped" :ajaxSettings="ajaxSettings">
</ejs-filemanager>
</div>
</template>
<script>
import { FileManagerComponent, DetailsView, NavigationPane, Toolbar } from "@syncfusion/ej2-vue-filemanager";
export default {
name: "App",
components: {
"ejs-filemanager":FileManagerComponent,
},
data () {
return {
ajaxSettings:
{
url: "https://ej2-aspcore-service.azurewebsites.net/api/FileManager/FileOperations",
getImageUrl: "https://ej2-aspcore-service.azurewebsites.net/api/FileManager/GetImage",
uploadUrl: "https://ej2-aspcore-service.azurewebsites.net/api/FileManager/Upload",
downloadUrl: "https://ej2-aspcore-service.azurewebsites.net/api/FileManager/Download"
},
allowDragAndDrop: true
};
},
provide: {
filemanager: [DetailsView, NavigationPane, Toolbar]
},
methods: {
// File Manager's file Drag start event function
onFileDragStart: function(){
console.log("File Drag Start");
},
// File Manager's file Drag stop event function
onFileDragStop: function(){
console.log("File Drag Stop");
},
// File Manager's file Dragging event function
onFileDragging: function(){
console.log("File Dragging");
},
// File Manager's file Dropped event function
onFileDropped: function(){
console.log("File Dropped");
}
}
}
</script>
<style>
@import "../node_modules/@syncfusion/ej2-base/styles/material.css";
@import "../node_modules/@syncfusion/ej2-icons/styles/material.css";
@import "../node_modules/@syncfusion/ej2-inputs/styles/material.css";
@import "../node_modules/@syncfusion/ej2-popups/styles/material.css";
@import "../node_modules/@syncfusion/ej2-buttons/styles/material.css";
@import "../node_modules/@syncfusion/ej2-splitbuttons/styles/material.css";
@import "../node_modules/@syncfusion/ej2-navigations/styles/material.css";
@import "../node_modules/@syncfusion/ej2-layouts/styles/material.css";
@import "../node_modules/@syncfusion/ej2-grids/styles/material.css";
@import "../node_modules/@syncfusion/ej2-vue-filemanager/styles/material.css";
</style>