1.0.9 • Published 1 year ago

create-file-input v1.0.9

Weekly downloads
-
License
MIT
Repository
-
Last release
1 year ago

快速打开文件选择窗口

无论是否选择了文件, 关闭后自动移除 input element

Installtion

npm i create-file-input
# or
yarn add create-file-input

Usage

import createFileInput from 'create-file-input'

// 基础使用
createFileInput({
  onChange: e => {
    const file = e.target.files[0]
    const formData = new FormData()
    formData.append('file', file)
  }
})

// 开启只要附件数据
createFileInput({
  fileOnly: true,
  onChange: file => {
    const formData = new FormData()
    formData.append('file', file)
  }
})

// 开启只要附件数据
createFileInput({
  fileOnly: true,
  multiple: true,
  onChange: files => {
    formData.append('file', files[0])
  }
})

Props

参数名说明默认值
accept允许选择的文件类型*
multiple是否多选false
fileOnly选择后的回调是否只需要文件数据false
onChange选择后的回调-
1.0.9

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago