elementUI上传组件on-success回调传参

5,385 阅读1分钟

多个上传组件时,想知道第几个组件上传成功,需要传参,一般是组件的index,传递方法如下:

<el-upload
  class="avatar-uploader"
  :show-file-list="false"
  :on-success="
    (response, file, fileList) =>
      handleAvatarSuccess(response, file, fileList, 0)
  "
  action="http://xxxxx"
>
  <img
    v-if="imageUrl[0]"
    :src="imageUrl[0]"
    class="avatar"
  />
  <i v-else class="el-icon-plus avatar-uploader-icon"></i>
</el-upload>

handleAvatarSuccess(res, file, fileList, index) {
  this.imageUrl[index] = res.result.fileSignUrl;
}

若是用v-for循环生成,0修改为index即可