Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Apply VueUse composables in Vue 3/Nuxt projects to replace custom implementations with battle-tested utilities.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/useDropZone.md
1---2category: Elements3---45# useDropZone67Create a zone where files can be dropped.89::: warning1011Due to Safari browser limitations, file type validation is only possible during the drop event, not during drag events. As a result, the `isOverDropZone` value will always be `true` during drag operations in Safari, regardless of file type.1213:::1415## Usage1617```vue18<script setup lang="ts">19import { useDropZone } from '@vueuse/core'20import { useTemplateRef } from 'vue'2122const dropZoneRef = useTemplateRef('dropZoneRef')2324function onDrop(files: File[] | null) {25// called when files are dropped on zone26}2728const { isOverDropZone } = useDropZone(dropZoneRef, {29onDrop,30// specify the types of data to be received.31dataTypes: ['image/jpeg'],32// control multi-file drop33multiple: true,34// whether to prevent default behavior for unhandled events35preventDefaultForUnhandled: false,36})37</script>3839<template>40<div ref="dropZoneRef">41Drop files here42</div>43</template>44```4546## Type Declarations4748```ts49export interface UseDropZoneReturn {50files: ShallowRef<File[] | null>51isOverDropZone: ShallowRef<boolean>52}53export interface UseDropZoneOptions {54/**55* Allowed data types, if not set, all data types are allowed.56* Also can be a function to check the data types.57*/58dataTypes?:59| MaybeRef<readonly string[]>60| ((types: readonly string[]) => boolean)61/**62* Similar to dataTypes, but exposes the DataTransferItemList for custom validation.63* If provided, this function takes precedence over dataTypes.64*/65checkValidity?: (items: DataTransferItemList) => boolean66onDrop?: (files: File[] | null, event: DragEvent) => void67onEnter?: (files: File[] | null, event: DragEvent) => void68onLeave?: (files: File[] | null, event: DragEvent) => void69onOver?: (files: File[] | null, event: DragEvent) => void70/**71* Allow multiple files to be dropped. Defaults to true.72*/73multiple?: boolean74/**75* Prevent default behavior for unhandled events. Defaults to false.76*/77preventDefaultForUnhandled?: boolean78}79export declare function useDropZone(80target: MaybeRefOrGetter<HTMLElement | Document | null | undefined>,81options?: UseDropZoneOptions | UseDropZoneOptions["onDrop"],82): UseDropZoneReturn83```84