vue 上传文件时,显示懒加载

在要加载的组上加上

<template slot-scope="scope" slot="pathForm">
          <el-upload
            class="avatar-uploader"
            action="/api/upload"
            :data="{
              FoldPath: '上传目录',
              SecretKey: '安全验证',
              isAsync: true
            }"
            :on-success="handleSuccess"
            :before-upload="beforeUpload"
            :show-file-list="false"
            :disabled="disabled"
            v-loading="uploading"//懒加载控件
          >
            <el-button v-if="form.path == ''" size="small" type="primary"
              >上传文件</el-button
            >

            <div v-else>{{ form.path }}</div>
            <icon icon="el-icon-loading" v-if="form.path == ''" />
          </el-upload>
        </template>

在data中定义

 data() {
    return {
      uploading: false,
    }
}

文件加载

 methods: {
    beforeUpload(file) {
      this.uploading = true;//上传时显示
      console.log(file);
      this.form.size = file.size;
      var fileSize = file.size / 1024 / 1024 < 100;
      this.$message("正在上传中,请稍后");
      if (
        // ["application/vnd.android.package-archive", ""].indexOf(file.type) == -1
        ["application/x-zip-compressed", ""].indexOf(file.type) == -1
      ) {
        this.$message("请上传正确的格式");
        return false;
      }
      if (!fileSize) {
        this.$message("文件大小不能超过100MB");
        return false;
      }
    },
    //上传成功回调
    handleSuccess(res, file) {
      //后台上传地址
      this.uploading = false;//无论是否成功懒加载都隐藏

      if (res.resultCode == 0) {
        this.$message.success("上传成功");
        this.form.path = res.resultData;
        console.log(res.resultData);
      } else {
        this.$message.error("上传失败,请重新上传");
      }
    },
}

效果图

 

 

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值