dom
<el-upload
class="avatar-uploader"
action="https://jsonplaceholder.typicode.com/posts/"
:http-request="uploadSectionFile"
:show-file-list="false"
:before-upload="beforeAvatarUpload">
<img v-if="scope.row.imgUrl" :src="scope.row.imgUrl" class="avatar">
<i v-else class="el-icon-plus avatar-uploader-icon"></i>
</el-upload>
js
uploadSectionFile(param){
var fileObj = param.file;
var form = new FormData();
form.append("file", fileObj);
let requestId = uuid.v1().replace(/-/g, '')
//
this.$http.post(`/commons_rest/file/upload?catalog=headimg&requestId=${requestId}`,
form,
{progress:function(event){
param.file.percent = event.loaded/event.total*100
param.onProgress(param.file)
}
}).then((res)=>{
console.log(res)
param.data.list.push({
name:res.data.name,
status:"success",
uid:new Date().getTime(),
url:res.data.url
})
},response => {
console.log('--->>>>>',response)
})
},
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者