主题
useFileDialog
轻松打开文件对话框。
¥Open file dialog with ease.
示例
用法
¥Usage
ts
import { useFileDialog } from '@vueuse/core'
const { files, open, reset, onCancel, onChange } = useFileDialog({
accept: 'image/*', // Set to accept only image files
directory: true, // Select directories instead of files if set true
})
onChange((files) => {
/** do something with files */
})
onCancel(() => {
/** do something on cancel */
})
vue
<template>
<button type="button" @click="open">
Choose file
</button>
</template>
类型声明
显示类型声明
typescript
export interface UseFileDialogOptions extends ConfigurableDocument {
/**
* @default true
*/
multiple?: boolean
/**
* @default '*'
*/
accept?: string
/**
* Select the input source for the capture file.
* @see [HTMLInputElement Capture](https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/capture)
*/
capture?: string
/**
* Reset when open file dialog.
* @default false
*/
reset?: boolean
/**
* Select directories instead of files.
* @see [HTMLInputElement webkitdirectory](https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/webkitdirectory)
* @default false
*/
directory?: boolean
}
export interface UseFileDialogReturn {
files: Ref<FileList | null>
open: (localOptions?: Partial<UseFileDialogOptions>) => void
reset: () => void
onChange: EventHookOn<FileList | null>
onCancel: EventHookOn
}
/**
* Open file dialog with ease.
*
* @see https://vueuse.org/useFileDialog
* @param options
*/
export declare function useFileDialog(
options?: UseFileDialogOptions,
): UseFileDialogReturn