コンテンツへスキップ

useFileDialog

カテゴリ
エクスポートサイズ
707 B
最終更新日
先週

簡単にファイルダイアログを開きます。

デモ

使用方法

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.dokyumento.jp/useFileDialog
 * @param options
 */
export declare function useFileDialog(
  options?: UseFileDialogOptions,
): UseFileDialogReturn

ソース

ソースデモドキュメント

コントリビューター

Anthony Fu
Anthony Fu
Andrey Yolkin
jinkaiqin
Doctorwu
huiliangShen
Sandra Rodgers
Damian Głowala
zaqvil
丶遠方
1SZX1
ZHAO Jinxiang
Max
Robert Soriano

変更ログ

v12.0.0-beta.1 2024/11/21
0a9ed - feat!: Vue 2サポートの削除、バンドルの最適化、クリーンアップ (#4349)
v11.1.0 2024/9/16
30452 - feat: onCancelハンドラの返却 (#4184)
v10.10.0 2024/5/27
424a2 - fix: onChangeをトリガーする前に入力値が存在するかどうかを確認する (#3972)
v10.7.0 2023/12/5
7e2da - feat: リセット時にonChangeをトリガーする (#3548)
v10.6.0 2023年11月9日
cefca - feat: ディレクトリパラメータを追加 (#3513)
v10.2.0 2023年6月16日
6d847 - feat: パラメータresetを追加 (#3059)
v10.0.0-beta.1 2023年3月23日
5e697 - feat: ファイル変更イベントのリスナーを追加 (#2893)

MITライセンスの下でリリースされています。