this.$message.error('Avatar picture must be JPG format!');
}
if (!isLt2M) {
this.$message.error('Avatar picture size can not exceed 2MB!');
}
return isJPG && isLt2M;
}
}
}
}
}
}
...
@@ -40,12 +58,13 @@ Upload files by clicking or drag-and-drop
...
@@ -40,12 +58,13 @@ Upload files by clicking or drag-and-drop
:::demo Customize upload button type and text using `slot`.
:::demo Customize upload button type and text using `slot`.
```html
```html
<el-upload
<el-upload
action="//jsonplaceholder.typicode.com/posts/"
class="upload-demo"
action="http://localhost:9000/upload"
:on-preview="handlePreview"
:on-preview="handlePreview"
:on-remove="handleRemove"
:on-remove="handleRemove"
:default-file-list="fileList">
:file-list="fileList">
<el-buttonsize="small"type="primary">Click to upload</el-button>
<el-buttonsize="small"type="primary">Click to upload</el-button>
<divclass="el-upload__tip"slot="tip">jpg/png files with a size less than 500kb</div>
<divslot="tip"class="el-upload__tip">jpg/png files with a size less than 500kb</div>
</el-upload>
</el-upload>
<script>
<script>
exportdefault{
exportdefault{
...
@@ -67,33 +86,65 @@ Upload files by clicking or drag-and-drop
...
@@ -67,33 +86,65 @@ Upload files by clicking or drag-and-drop
```
```
:::
:::
### Drag to upload
### User avatar upload
You can drag your file to a certain area to upload it.
Use beforeUpload hook to limit the upload file format and size.
:::demo Specifying the `type` attribute as `drag` will change the upload control to a drag-and-drop style. Additionally, you can use the `multiple` attribute to control whether uploading multiple files is permitted. `on-preview` and `on-remove` are hook functions that will be called after clicking on the uploaded file link and after clicking to remove the uploaded file, respectively.
on-preview | hook function when clicking the uploaded files | function(file) | — | —
on-preview | hook function when clicking the uploaded files | function(file) | — | —
on-remove | hook function when files are removed | function(file, fileList) | — | —
on-remove | hook function when files are removed | function(file, fileList) | — | —
on-success | hook function when uploaded successfully | function(response, file, fileList) | — | —
on-success | hook function when uploaded successfully | function(response, file, fileList) | — | —
on-error | hook function when some errors occurs | function(err, response, file) | — | —
on-error | hook function when some errors occurs | function(err, file, fileList) | — | —
on-progress | hook function when some progress occurs | function(event, file, fileList) | — | — |
on-progress | hook function when some progress occurs | function(event, file, fileList) | — | — |
on-change | hook function when file status change | function(file, fileList) | — | — |
before-upload | hook function before uploading with the file to be uploaded as its parameter. If `false` or a `Promise` is returned, uploading will be aborted | function(file) | — | —
before-upload | hook function before uploading with the file to be uploaded as its parameter. If `false` or a `Promise` is returned, uploading will be aborted | function(file) | — | —