Skip to content

useFileDialog

类别
导出体积
702 B
上次更改
1 hour ago

轻松打开文件对话框。

示例

使用方法

vue
<script setup lang="ts">
import { 
useFileDialog
} from '@vueuse/core'
const {
files
,
open
,
reset
,
onCancel
,
onChange
} =
useFileDialog
({
accept
: 'image/*', // 设置仅接受图像文件
directory
: true, // 如果设置为 true,则选择目录而不是文件
})
onChange
((
files
) => {
/** 处理文件 */ })
onCancel
(() => {
/** 在取消时做一些事情 */ }) </script> <template> <
button
type
="button" @
click
="
open
">
选择文件 </
button
>
</template>

类型声明

显示类型声明
ts
export interface UseFileDialogOptions extends ConfigurableDocument {
  /**
   * @default true
   */
  
multiple
?:
MaybeRef
<boolean>
/** * @default '*' */
accept
?:
MaybeRef
<string>
/** * 选择捕获文件的输入源。 * @see [HTMLInputElement Capture](https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/capture) */
capture
?:
MaybeRef
<string>
/** * 打开文件对话框时重置。 * @default false */
reset
?:
MaybeRef
<boolean>
/** * 选择目录而不是文件。 * @see [HTMLInputElement webkitdirectory](https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/webkitdirectory) * @default false */
directory
?:
MaybeRef
<boolean>
/** * Initial files to set. * @default null */
initialFiles
?:
Array
<File> | FileList
/** * The input element to use for file dialog. * @default document.createElement('input') */
input
?:
MaybeElementRef
<HTMLInputElement>
} export interface UseFileDialogReturn {
files
:
Ref
<FileList | null>
open
: (
localOptions
?:
Partial
<UseFileDialogOptions>) => void
reset
: () => void
onChange
:
EventHookOn
<FileList | null>
onCancel
:
EventHookOn
} /** * 轻松打开文件对话框。 * * @see https://vueuse.org/useFileDialog * @param options */ export declare function
useFileDialog
(
options
?: UseFileDialogOptions,
): UseFileDialogReturn

源码

源码演示文档

贡献者

一纸忘忧

更新日志

没有最近的更新日志