0


Element-ui upload 手动上传文件

element 手动上传

(随手一发,可以拿过来就用,不做解释看不懂的可以照搬,👇代码可复制👇)

<div>
 <el-upload
   class="upload"
   ref="upload"
   action="string"
   :file-list="fileList"
   :auto-upload="false"
   :http-request="uploadFile"
   :on-change="handleChange"
   :on-preview="handlePreview"
   :on-remove="handleRemove"
   multiple="multiple"
 >
  <el-button
   slot="trigger"
   size="small"
   @click="delFile"
   class="chaxuns fontSizes"
  >选取文件</el-button>
  <div class="upfile">
   <el-button
     style="margin-left: 10px;"
     size="small"
     type="success"
     class="chaxuns fontSizes"
     @click="submitUpload"
   >上传文件</el-button>
  </div>
 </el-upload>          
</div>
    // 选取文件
    delFile() {
      this.fileList = [];
    },
    handleChange(file, fileList) {
      this.fileList = fileList;
    },
    uploadFile(file) {
      this.formData.append("file", file.file);
    },
    submitUpload() {
      const formData = new FormData();
      formData.append("file", this.fileList[0].raw);
      // ↓后端请求接口↓
      upload(formData).then(res => {
        if (res.data.length === 0) {
          this.$message.warning("上传失败")
          this.fileList = [];
        } else {
          this.$message.success("上传文件成功")
          this.fileList = [];
        }
      })
    },

本文转载自: https://blog.csdn.net/weixin_45333397/article/details/128813085
版权归原作者 写代码的小菜鸡丶 所有, 如有侵权,请联系我们删除。

“Element-ui upload 手动上传文件”的评论:

还没有评论