feat(Uploader): max-size prop can be a function (#8744)

* feat(Uploader): max-size prop can be a function

* chore: revert demo

* test: fix snapshot

* docs: upd
This commit is contained in:
neverland
2021-05-22 20:30:09 +08:00
committed by GitHub
parent 5b6dadc39f
commit 833064adbd
5 changed files with 94 additions and 12 deletions
+25 -3
View File
@@ -146,6 +146,28 @@ export default {
};
```
If you need to make different size limits for different types of files, you can pass a function to the `max-size` props.
```html
<van-uploader multiple :max-size="isOverSize" />
```
```js
import { Toast } from 'vant';
export default {
setup() {
const isOverSize = (file) => {
const maxSize = file.type === 'image/jpeg' ? 500 * 1024 : 1000 * 1024;
return file.size >= maxSize;
};
return {
isOverSize,
};
},
};
```
### Custom Upload Area
```html
@@ -274,7 +296,7 @@ export default {
| name | Input name | _number \| string_ | - |
| preview-size | Size of preview image | _number \| string_ | `80px` |
| preview-image | Whether to show image preview | _boolean_ | `true` |
| preview-full-image | Whethe to show full screen image preview when image is clicked | _boolean_ | `true` |
| preview-full-image | Whether to show full screen image preview when image is clicked | _boolean_ | `true` |
| preview-options | Options of full screen image previewsee [ImagePreview](#/en-US/image-preview) | _object_ | - |
| multiple | Whether to enable multiple selection pictures | _boolean_ | `false` |
| disabled | Whether to disabled the upload | _boolean_ | `false` |
@@ -285,7 +307,7 @@ export default {
| after-read | Hook after reading the file | _Function_ | - |
| before-read | Hook before reading the file, return false to stop reading the file, can return Promise | _Function_ | - |
| before-delete | Hook before delete the file, return false to stop reading the file, can return Promise | _Function_ | - |
| max-size | Max size of file | _number \| string_ | - |
| max-size `v3.0.17` | Max size of file | _number \| string \| (file: File) => boolean_ | - |
| max-count | Max count of image | _number \| string_ | - |
| result-type | Type of file read result, can be set to `file` `text` | _string_ | `dataUrl` |
| upload-text | Upload text | _string_ | - |
@@ -308,7 +330,7 @@ export default {
| default | Custom icon | - |
| preview-cover | Custom content that covers the image preview | `item: FileListItem` |
### Parematers of before-read、after-read、before-delete
### Parameters of before-read、after-read、before-delete
| Attribute | Description | Type |
| --------- | ------------------------------------ | -------- |