<el-form-item label="截圖">
<el-upload
class="upload-demo"
accept="image/png,image/jpg,image/jpeg"
ref="upload"
:file-list="fileLists"
action="#"
:on-change="handlePreview"
:on-remove="handleRemove"
list-type="picture-card"
:limit="2"
:on-exceed="fileExceed"
:auto-upload="false">
<i class="el-icon-plus"></i>
</el-upload>
<el-button size="small" type="success" @click="submit">確定</el-button>
</el-form-item>
data() {
return {
fileLists: [],
};
},
handleRemove(file, fileList) {
this.fileLists = fileList;
},
handlePreview(file, fileList) {
let that = this;
console.log(file)
if (file.raw.type !== 'image/jpg' && file.raw.type !== 'image/png') {
that.$message.error('圖片只能是jpg/png格式!');
return;
}
if (file.raw.size > 1024 * 1024 * 2) {
that.$message.error('上傳文件大小不能超過 2MB!');
return;
}
that.fileLists = fileList;
},
fileExceed:function(files, fileList){
this.$message.warning(`當前限制選擇 2 個文件,本次選擇了 ${files.length} 個文件,共選擇了 ${fileList.length} 個文件`)
},
submit() {
console.log(this.fileLists)
}