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/useFileDialog.md
1---2category: Browser3---45# useFileDialog67Open file dialog with ease.89## Usage1011```vue12<script setup lang="ts">13import { useFileDialog } from '@vueuse/core'1415const { files, open, reset, onCancel, onChange } = useFileDialog({16accept: 'image/*', // Set to accept only image files17directory: true, // Select directories instead of files if set true18})1920onChange((files) => {21/** do something with files */22})2324onCancel(() => {25/** do something on cancel */26})27</script>2829<template>30<button type="button" @click="open">31Choose file32</button>33</template>34```3536## Type Declarations3738```ts39export interface UseFileDialogOptions extends ConfigurableDocument {40/**41* @default true42*/43multiple?: MaybeRef<boolean>44/**45* @default '*'46*/47accept?: MaybeRef<string>48/**49* Select the input source for the capture file.50* @see [HTMLInputElement Capture](https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/capture)51*/52capture?: MaybeRef<string>53/**54* Reset when open file dialog.55* @default false56*/57reset?: MaybeRef<boolean>58/**59* Select directories instead of files.60* @see [HTMLInputElement webkitdirectory](https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/webkitdirectory)61* @default false62*/63directory?: MaybeRef<boolean>64/**65* Initial files to set.66* @default null67*/68initialFiles?: Array<File> | FileList69/**70* The input element to use for file dialog.71* @default document.createElement('input')72*/73input?: MaybeElementRef<HTMLInputElement>74}75export interface UseFileDialogReturn {76files: Ref<FileList | null>77open: (localOptions?: Partial<UseFileDialogOptions>) => void78reset: () => void79onChange: EventHookOn<FileList | null>80onCancel: EventHookOn81}82/**83* Open file dialog with ease.84*85* @see https://vueuse.org/useFileDialog86* @param options87*/88export declare function useFileDialog(89options?: UseFileDialogOptions,90): UseFileDialogReturn91```92