element upload 自定义上传 报错Cannot set properties of null (setting ‘status‘)

文章讲述了在ElementUI的自定义上传功能中遇到Cannotsetpropertiesofnull(settingstatus)的问题,通过设置`auto-upload`属性为`false`解决了这个问题。开发者需注意当action为空时,需要手动处理上传逻辑。
摘要由CSDN通过智能技术生成

element upload 自定义上传 报错Cannot set properties of null (setting ‘status’)

问题展示

问题展示

原因分析

自定义上传方式
fileList 显示一切正常,状态也是成功
文件url通过URL.createObjectURL(file.raw) 进行添加
以下为配置代码

<el-upload
  class="upload-demo"
  action=""
  :on-change="uploadImageChange"
  :on-remove="handleRemove"
  :before-remove="beforeRemove"
  multiple
  :limit="1"
  :on-exceed="handleExceed"
  :file-list="fileList"
>
  <el-button size="small" type="primary">点击上传</el-button>
  <div slot="tip" class="el-upload__tip" style="font-size: 11px;">只能上传svg文件,且不超过500kb</div>
</el-upload>

以下为fileList 添加代码

that.fileList = [{ name: new Date().getTime(), url: URL.createObjectURL(res.raw) }]
问题修复

在组件上添加以下代码

:auto-upload="false"

完整代码如下所示

<el-upload
 class="upload-demo"
  action=""
  :on-change="uploadImageChange"
  :on-remove="handleRemove"
  :before-remove="beforeRemove"
  :auto-upload="false"
  multiple
  :limit="1"
  :on-exceed="handleExceed"
  :file-list="fileList"
>
  <el-button size="small" type="primary">点击上传</el-button>
  <div slot="tip" class="el-upload__tip" style="font-size: 11px;">只能上传svg文件,且不超过500kb</div>
</el-upload>

添加后问题即可修复

注意

本文上传方式为自定义上传action 为空,因此需要添加:auto-upload=“false”

  • 9
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值