适用于一个页面,上传多个不同图片
比如这种情况:
template代码
重点: :on-success=“handleAvatarSuccess1.bind(this,‘head’)”
<el-form-item label="医生头像" prop="name">
<el-upload
class="avatar-uploader"
name="file"
:action="UPLOAD_HOST"
:show-file-list="false"
:on-success="handleAvatarSuccess1.bind(this,'head')"
>
<img v-if="form.headUrl" :src="form.headUrl" class="avatar">
<div v-else class="el-icon-plus avatar-uploader-icon">
<span></span>
<div >上传</div>
</div>
</el-upload>
methods代码
其中name为传进去的参数
methods: {
// 处理el图片上传
handleAvatarSuccess1(name,res) {
console.log(res,88888888888,type);
const {httpCode, result} = res;
if (httpCode == 200) {
this.form.headUrl = result.fileName;
console.log(this.form.headUrl);
}else {
this.$message('上传图片出错')
}
参考:
https://www.xhcss.com/xh/vuejc/vuecjwt/423.html
https://segmentfault.com/q/1010000013727322/a-1020000013732423