useDropZone ​
Create a zone where files can be dropped.
Demo ​
Drop files on to drop zones
PNG
SVG
General DropZone
isOverDropZone: false
Image DropZone
isOverDropZone: false
Usage ​
vue
<script setup lang="ts">
import { useDropZone } from '@vueuse/core'
const dropZoneRef = ref<HTMLDivElement>()
function onDrop(files: File[] | null) {
// called when files are dropped on zone
}
const { isOverDropZone } = useDropZone(dropZoneRef, {
onDrop,
// specify the types of data to be received.
dataTypes: ['image/jpeg']
})
</script>
<template>
<div ref="dropZoneRef">
Drop files here
</div>
</template>
Type Declarations ​
typescript
export interface UseDropZoneReturn {
files: Ref<File[] | null>
isOverDropZone: Ref<boolean>
}
export interface UseDropZoneOptions {
/**
* Allowed data types, if not set, all data types are allowed.
* Also can be a function to check the data types.
*/
dataTypes?: MaybeRef<string[]> | ((types: readonly string[]) => boolean)
onDrop?: (files: File[] | null, event: DragEvent) => void
onEnter?: (files: File[] | null, event: DragEvent) => void
onLeave?: (files: File[] | null, event: DragEvent) => void
onOver?: (files: File[] | null, event: DragEvent) => void
}
export declare function useDropZone(
target: MaybeRefOrGetter<HTMLElement | null | undefined>,
options?: UseDropZoneOptions | UseDropZoneOptions["onDrop"],
): UseDropZoneReturn
Source ​
Contributors ​
Anthony Fu
Diego Pascual
getname1997
Neo Fu
Luka Bagic
aki77
Matthias Stiller
Julien Martin