<el-upload
class="upload-demo"
:action="uploadaction"
:on-success="handleSuccess"
:on-error="handleError"
:before-upload="beforeUpload"
:file-list="fileList"
:limit="1"
:accept="imageAccept"
>
<el-button slot="trigger" size="small" type="primary">选择图片</el-button>
<div slot="tip" class="upload-tip">只能上传一张图片</div>
</el-upload>
uploadaction: this.constant.loadurl.uploadThumbnail +"?token=" +localStorage.getItem("token"), //上传缩略图路径
fileList: [], // 用于存储已上传的文件列表
imageAccept: 'image/*', // 限制上传的文件类型为图片
handleSuccess(response, file, fileList) {
// 上传成功的处理逻辑
console.log('上传成功', response);
},
handleError(error, file, fileList) {
// 上传失败的处理逻辑
console.log('上传失败', error);
},
beforeUpload(file) {
// 文件上传前的处理逻辑,例如限制文件大小等
console.log('准备上传', file);
},