<el-upload
class="upload-demo"
list-type="picture"
accept="image/*"
:show-file-list="false"
:multiple="false"
:auto-upload="false"
action="https://jsonplaceholder.typicode.com/posts/"
:on-change="(file, fileList) => {handleChange(file, fileList, name)}"
:on-preview="handlePreview">
</el-upload>
// 上传文件
handleChangeFile(file, fileList, name) {
const isLt10M = file.size / 1024 / 1024 < 10
if (!this.$checkFileType(file.raw.name, ['png', 'jpg', 'jpeg'])) {
this.$message.error('只能上传png、jpg、jpeg格式文件!')
return false
} else if (!isLt10M) {
this.$message.error('上传文件大小不能超过 10MB!')
return false
}
// let formdata = new FormData()
// formdata.append('templateFile', file.raw)
this.postData[name] = file.raw
console.log(this.postData)
},