【vue】使用el-upload 上传图片,遇到的问题

<el-upload
    class="upload-demo"
    ref="paymentUpload"
    :action="uploadUrl"
    :on-preview="handlePictureCardPreview"
    :on-remove="handleRemove"
    :file-list="orderInfo.payment_voucher"
    :on-success="handlepaymentSuccess"    
    :on-change="handlepaymentChange">
    <div> <el-button type="text" class="upload-btn">上传</el-button></div>
</el-upload>

问题一:上传一个文件后在handlepaymentSuccess中打印this.orderInfo.payment_voucher 效果如下

 

 故:如果想接口中传这个值时需要赋值

问题二:重组数据列表结构数据列表闪烁问题调研

代码

//上传成功
handlepaymentSuccess(response,file, fileList){
    //这样写会造成1.上传的时候页面闪烁,2.删除后重新上传之前上传的还存在(待研究)
    let data = {
        name: file.name,
        url: file.response.data.fileurl,
    };
    this.orderInfo.payment_voucher.push(data);
    console.log(this.orderInfo.payment_voucher);
},

产生的问题:

  • 上传列表闪动
  • 为何重组的数据中有status,uid字段
  • 删除后重新上传之前上传的还会存在

1、闪动问题方案一(没有效果):

/deep/.el-upload-list__item.is-ready {
  display: none;
}

链接:elementUi el-upload上传图片时图片闪烁

2、闪动问题解决方案:

handlepaymentSuccess(response,file, fileList){
    this.orderInfo.payment_voucher = fileList;
},

ps:问题解决了,可是不知道为何要如此操作(这样操作后,移除操作中不需要写什么)

链接:饿了么UI组件库中,Upload组件上传闪动的解决

可是还是还没有解决为何重组的数据中会有其他的字段,待解决

 3、删除后重新上传之前上传的还会存在

//删除上传列表
handleRemove(file, fileList) {
    this.orderInfo.payment_voucher = fileList;
},
原文地址:https://www.cnblogs.com/websmile/p/13652622.html