elementUI:Upload组件list-type: picture-card上传闪动

这篇博客介绍了如何利用饿了么UI组件库中的Upload组件,解决在前端开发中遇到的多图上传及上传过程中图片闪动的问题。通过设置file-list、on-success、on-remove等属性,自定义上传逻辑,并结合formData进行文件提交,确保图片上传的成功与用户体验。同时,提供了处理添加、移除文件的方法,确保文件列表的正确管理。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

直接push file对象 可以解决

多图上传示例

<el-upload
        action="action"
        list-type="picture-card"
        name="image"
        :file-list="files"
        :on-remove="handleRemove"
        :on-success="handleSuccess"
        :http-request="uploadFile"
      >
        <i class="el-icon-plus"></i>
</el-upload>

props: {
    // 引用传递数组 { name, url }
    files: { type: Array, default: null },
 },
 
methods: {
     // 自定义实现文件上传
     async uploadFile(params) {
      let form = new FormData();
      form.append('image', params.file);
      const res = await this.$Http.commonUpload(form);
      return res;
    },
    
	// 处理添加
	handleSuccess(response, file, fileList) {
	   // 设置url
	   file.url = response.data.url;
	   this.files.push(file);
	},
	
	// 移除
	handleRemove(file, fileList) {
		this.files.splice(0, this.files.length, ...fileList);
	}
} 

参考
饿了么UI组件库中,Upload组件上传闪动的解决

评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值