element上传下载文件

上传文件:
<el-upload
  class="upload-demo"
  action
  accept=".png, .jpg"
  :http-request="AvatarUpload"
  :limit="1"
  :file-list="fileList"
  list-type="picture"
>
  <el-button size="small" type="primary">点击上传</el-button>
  <div slot="tip" class="el-upload__tip">只能上传jpg/png文件,且不超过500kb</div>
</el-upload>
<el-button
  type="primary"
  @click="submitForm('ruleForm')"
  size="medium"
  v-loading.fullscreen.lock="submitLoading"
>提交</el-button>
 
   fileList: [],  //data
   
AvatarUpload(param) {  //方法
  const isLt500 = param.file.size / 1024 < 500;
  if (!isLt500) {
    this.$message.error("上传地图ICON图片大小不能超过 500KB!");
  } else {
    const file = param.file;
    const reader = new FileReader();
    reader.readAsDataURL(file); // readAsDataURL自带方法
    reader.onload = () => {
      this.ruleForm.icon = reader.result;
    };
  }
},
submitForm(formName) {
  if (this.ruleForm.id) {
    this.updateZone(formName);
  } else {
    this.creatZone(formName);
  }
},
下载文件:
// 下载文件
        handleDownload1(row) {
            download(row.id).then(res => {
                if (res && res.data) {
                    var blob = new Blob([res.data], {
                        type: "application/json;charset=utf-8"
                    });
                    var url = window.URL.createObjectURL(blob);
                    var aLink = document.createElement("a");
                    aLink.style.display = "none";
                    aLink.href = url;
                    aLink.setAttribute("download", row.name + "shape.zip");
                    document.body.appendChild(aLink);
                    aLink.click();
                    document.body.removeChild(aLink); // 下载完成移除元素
                    window.URL.revokeObjectURL(url); // 释放掉blob对象
                }
            });
        },
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值