element ui 文件上传不能手动触发

clipboard.png

<div class="pass" v-for="(item,index) in showList">
 <el-upload class="avatar-uploader" :accept="accept" action="https://upload.qiniup.com" :show- 
   file-list="false" @on-success="handleAvatarSuccess" :before-upload="beforeAvatarUpload" 
       :data="postData" ref="uploadAdd" :on-change="handleChange" :auto-upload="false">
    <div class="add text-center ">
      <span>新增</span>
    </div>
    </el-upload>
  </div>
   <!-- 新增弹框 -->
<div class="elDialog">
  <el-dialog :visible.sync="mView" width="530px" height="200px">
    <span @click="mViewClose" class="closeDialog"></span>
    <div class="text-center mViewContent">
      <el-form :rules="rules" status-icon class="demo-ruleForm" :model="sideForm" ref="sideForm">
        <el-form-item :label-width="formLabelWidth" prop="materName">
          <el-input v-model="sideForm.materName" placeholder="请输入材料名称"></el-input>
        </el-form-item>
        <el-form-item :label-width="formLabelWidth" prop="materRemark">
          <el-input v-model="sideForm.materRemark" placeholder="请输入备注"></el-input>
        </el-form-item>
      </el-form>
      <div class="matter">
        <p class="font-14">{{fileName}}<span>更改文件</span></p>
      </div>
      <el-button type="primary" round @click="trueUpdate(sideForm)">确认上传</el-button>
    </div>
  </el-dialog>
</div>

##

trueUpdate(sideForm) { //确认上传
      this.mView = false;
      this.$refs.uploadAdd.submit();
  });
},

##
dom里面我循环了4个新增,点击新增就会选择文件,当文件选择后出现弹框。然后点击确认上传,手动触发上传。但是报错。一直不能上传。我新增弹框4个共用的一个。

clipboard.png

阅读 9.5k
2 个回答

当你不使用element上传后,你就应该自己做的啊,element只是帮你做了选择文件后,按照文件上传格式传上去,如果你中断了。那你自己就拼接即可

const formDate = new FormData()
formData.append('file', File)
axios.post(url, formData)

即可。

refs文档,使用V-for的话,这里将会形成的就是uploadAdd这样一个数组,你可能需要对数组中的每一个来submit

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题