-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
250 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
# UseUpload | ||
|
||
upload file | ||
|
||
## Example | ||
|
||
### Basic Usage | ||
|
||
```ts | ||
<script setup lang="ts"> | ||
import { useUpload } from '@noi/core' | ||
|
||
const { files, append, upload } = useUpload({ url: '#' }) | ||
|
||
const onChange = (event) => { | ||
append(event.target.files) | ||
} | ||
</script> | ||
``` | ||
|
||
```html | ||
<template> | ||
{{ files }} | ||
<input type="file" @change="onChange" multiple /> | ||
<button @click="upload()">Upload</button> | ||
</template> | ||
``` | ||
|
||
### Limit file types | ||
|
||
```ts | ||
<script setup lang="ts"> | ||
import { useUpload } from '@noi/core' | ||
|
||
const accept = 'image/*' | ||
const { files, append, upload } = useUpload({ url: '#', accept }) | ||
|
||
const onChange = (event) => { | ||
append(event.target.files) | ||
} | ||
</script> | ||
``` | ||
|
||
```html | ||
<template> | ||
{{ files }} | ||
<input type="file" @change="onChange" :accept="accept" multiple /> | ||
<button @click="upload()">Upload</button> | ||
</template> | ||
``` | ||
|
||
### Limit file size | ||
|
||
```ts | ||
<script setup lang="ts"> | ||
import { useUpload } from '@noi/core' | ||
|
||
const { files, append, upload } = useUpload({ url: '#', maxSize: 1000 }) | ||
|
||
const onChange = (event) => { | ||
append(event.target.files) | ||
} | ||
</script> | ||
``` | ||
|
||
```html | ||
<template> | ||
{{ files }} | ||
<input type="file" @change="onChange" :accept="accept" multiple /> | ||
<button @click="upload()">Upload</button> | ||
</template> | ||
``` | ||
|
||
### Limit upload count | ||
|
||
```ts | ||
<script setup lang="ts"> | ||
import { useUpload } from '@noi/core' | ||
|
||
const accept = 'image/*' | ||
const { files, append, upload } = useUpload({ url: '#', maxCount: 2 }) | ||
|
||
const onChange = (event) => { | ||
append(event.target.files) | ||
} | ||
</script> | ||
``` | ||
|
||
```html | ||
<template> | ||
{{ files }} | ||
<input type="file" @change="onChange" :accept="accept" multiple /> | ||
<button @click="upload()">Upload</button> | ||
</template> | ||
``` | ||
|
||
## Types | ||
|
||
### UseUploadOptions | ||
|
||
| Name | Type | Default | Require | Description | | ||
| -------- | -------- | -------- | ------- | -------------------- | | ||
| url | _number_ | - | [x] | 上传文件的服务器地址 | | ||
| accept | _string_ | '' | [ ] | 允许上传的文件类型 | | ||
| maxSize | _number_ | Infinity | [ ] | 最大可上传的文件大小 | | ||
| maxCount | _number_ | Infinity | [ ] | 最多可上传的文件数量 | | ||
|
||
### UseUploadReturn | ||
|
||
| Name | Type | Description | | ||
| ------ | ------------------------------------------------ | ------------------ | | ||
| files | _Ref\<UseUploadFile[]\>_ | 当前添加的文件列表 | | ||
| append | _(file: File \| File[]) => Promise<void>_ | 添加文件方法 | | ||
| upload | _(index: number \| number[]) => void_ | 上传方法 | | ||
| remove | _(index: number \| number[]) => UseUploadFile[]_ | 删除文件方法 | | ||
|
||
### UseUploadFile | ||
|
||
| Name | Type | Description | | ||
| ------ | ------------------------------------------------ | ---------------------------- | | ||
| file | _File_ | 文件源数据 | | ||
| name | _string_ | 文件名 | | ||
| ext | _string_ | 扩展名 | | ||
| data | _string \| ArrayBuffer_ | base64数据,用于图片文件预览 | | ||
| status | _'ready' \| 'uploading' \| 'success' \| 'error'_ | 上传状态 | | ||
| error | _Error_ | 上传失败原因 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,126 @@ | ||
# UseUpload | ||
|
||
上传文件 | ||
上传文件 | ||
|
||
## 用法 | ||
|
||
### 基础用法 | ||
|
||
```ts | ||
<script setup lang="ts"> | ||
import { useUpload } from '@noi/core' | ||
|
||
const { files, append, upload } = useUpload({ url: '#' }) | ||
|
||
const onChange = (event) => { | ||
append(event.target.files) | ||
} | ||
</script> | ||
``` | ||
|
||
```html | ||
<template> | ||
{{ files }} | ||
<input type="file" @change="onChange" multiple /> | ||
<button @click="upload()">上传</button> | ||
</template> | ||
``` | ||
|
||
### 设置允许上传的文件类型 | ||
|
||
```ts | ||
<script setup lang="ts"> | ||
import { useUpload } from '@noi/core' | ||
|
||
const accept = 'image/*' | ||
const { files, append, upload } = useUpload({ url: '#', accept }) | ||
|
||
const onChange = (event) => { | ||
append(event.target.files) | ||
} | ||
</script> | ||
``` | ||
|
||
```html | ||
<template> | ||
{{ files }} | ||
<input type="file" @change="onChange" :accept="accept" multiple /> | ||
<button @click="upload()">上传</button> | ||
</template> | ||
``` | ||
|
||
### 限制上传文件大小 | ||
|
||
```ts | ||
<script setup lang="ts"> | ||
import { useUpload } from '@noi/core' | ||
|
||
const { files, append, upload } = useUpload({ url: '#', maxSize: 1000 }) | ||
|
||
const onChange = (event) => { | ||
append(event.target.files) | ||
} | ||
</script> | ||
``` | ||
|
||
```html | ||
<template> | ||
{{ files }} | ||
<input type="file" @change="onChange" :accept="accept" multiple /> | ||
<button @click="upload()">上传</button> | ||
</template> | ||
``` | ||
|
||
### 限制上传文件数量 | ||
|
||
```ts | ||
<script setup lang="ts"> | ||
import { useUpload } from '@noi/core' | ||
|
||
const accept = 'image/*' | ||
const { files, append, upload } = useUpload({ url: '#', maxCount: 2 }) | ||
|
||
const onChange = (event) => { | ||
append(event.target.files) | ||
} | ||
</script> | ||
``` | ||
|
||
```html | ||
<template> | ||
{{ files }} | ||
<input type="file" @change="onChange" :accept="accept" multiple /> | ||
<button @click="upload()">上传</button> | ||
</template> | ||
``` | ||
|
||
## 类型定义 | ||
|
||
### UseUploadOptions | ||
|
||
| 名称 | 类型 | 默认值 | 是否必传 | 说明 | | ||
| -------- | -------- | -------- | -------- | -------------------- | | ||
| url | _number_ | - | [x] | 上传文件的服务器地址 | | ||
| accept | _string_ | '' | [ ] | 允许上传的文件类型 | | ||
| maxSize | _number_ | Infinity | [ ] | 最大可上传的文件大小 | | ||
| maxCount | _number_ | Infinity | [ ] | 最多可上传的文件数量 | | ||
|
||
### UseUploadReturn | ||
|
||
| 名称 | 类型 | 说明 | | ||
| ------ | ------------------------------------------------ | ------------------ | | ||
| files | _Ref\<UseUploadFile[]\>_ | 当前添加的文件列表 | | ||
| append | _(file: File \| File[]) => Promise<void>_ | 添加文件方法 | | ||
| upload | _(index: number \| number[]) => void_ | 上传方法 | | ||
| remove | _(index: number \| number[]) => UseUploadFile[]_ | 删除文件方法 | | ||
|
||
### UseUploadFile | ||
|
||
| 名称 | 类型 | 说明 | | ||
| ------ | ------------------------------------------------ | ---------------------------- | | ||
| file | _File_ | 文件源数据 | | ||
| name | _string_ | 文件名 | | ||
| ext | _string_ | 扩展名 | | ||
| data | _string \| ArrayBuffer_ | base64数据,用于图片文件预览 | | ||
| status | _'ready' \| 'uploading' \| 'success' \| 'error'_ | 上传状态 | | ||
| error | _Error_ | 上传失败原因 | |