vue elementui文件

该博客详细介绍了如何使用前端组件实现图片和视频的上传功能,包括文件类型检查、预览及上传事件处理。主要涉及的技术点有:Element UI 的上传组件、FileReader API 用于图片预览以及文件类型验证确保上传内容为图片。
摘要由CSDN通过智能技术生成
<el-upload
              action
            v-model="imageUrl.file"
            :show-file-list="false"
            :before-upload="beforeAvatarUpload"
            :on-change="uploadSectionFile"
            list-type="picture-card"
          >
            <img
              style="height: 150px; width: 150px"
              v-if="imageUrl.url"
              :src="imageUrl.url"
            />
            <i v-else class="el-icon-plus avatar-uploader-icon"></i>
          </el-upload>



  uploadSectionFile(file) {
      console.log(file.raw, "文件上传");
      const typeArr = ["image/png", "image/gif", "image/jpeg", "image/jpg"];
      const isJPG = typeArr.indexOf(file.raw.type) !== -1;
      if (!isJPG) {
        this.$message.error("只能是图片!");
        return;
      }
    },

beforeAvatarUpload(file) {
      this.imageUrl.file = file;
      this.imagePreview(this.imageUrl.file, 1);
      return false;
    },

 imagePreview(file, v) {
      var self = this;
      //定义一个文件阅读器
      var reader = new FileReader();
      //文件装载后将其显示在图片预览里
      reader.onload = function (e) {
        //将bade64位图片保存至数组里供上面图片显示
        if (v == 1) {
          self.imageUrl.url = e.target.result;
        } else {
          self.vedioUrl.url = e.target.result;
        }
      };
      reader.readAsDataURL(file);
    },

视频上传同理

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值