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
:::demo Customize upload button type and text using `slot`.
```html
<el-upload
action="//jsonplaceholder.typicode.com/posts/"
class="upload-demo"
action="http://localhost:9000/upload"
:on-preview="handlePreview"
:on-remove="handleRemove"
:default-file-list="fileList">
:file-list="fileList">
<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>
<script>
exportdefault{
...
...
@@ -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.
::: demo
```html
<el-upload
action="//jsonplaceholder.typicode.com/posts/"
type="drag"
:multiple="true"
:on-preview="handlePreview"
:on-remove="handleRemove"
:on-success="handleSuccess"
:on-error="handleError"
:default-file-list="fileList"
>
<iclass="el-icon-upload"></i>
<divclass="el-dragger__text">Drop file here or <em>click to upload</em></div>
<divclass="el-upload__tip"slot="tip">jpg/png files with a size less than 500kb</div>
on-preview | hook function when clicking the uploaded files | function(file) | — | —
on-remove | hook function when files are removed | function(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-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) | — | —