Vant 上传/录制视频文件,显示预览图,支持视频预览,上传base64到后台

html代码

<van-uploader
            v-model="videoList"
            :max-count="1"
            preview-size="120px"
            accept="video/*"
            :after-read="handlevideosc"
            :before-read="handlebefread"
            @click-preview="handleclicksc"
          >
            <div slot="preview-cover">
              <video
                style="width:120px;height:120px;object-fit:cover;"
                :src="videourl"
                v-if="videourl"
              ></video>
            </div>
          </van-uploader>
          <div style="font-size:12px;color:#777">视频大小不能超过100M</div>
          <van-dialog
            style="width:100%;border-radius:0;height:200px"
            theme="default"
            v-model="showvideoplay"
            :show-cancel-button="false"
            :show-confirm-button="false"
            closeOnClickOverlay
          >
            <video
              controls
              preload="auto"
              style="width:100%;height:200px;object-fit: contain;"
              :src="videourl"
              v-if="videourl"
            ></video>
          </van-dialog>

js代码

data() {
    return {
      carinfo: {
        videofile: "",
        ngEcoOpenNo: ""
      },
      videoList: [],
      videourl: "",
      showvideoplay: false
    };
  },
  methods: {
    handlebefread(e) {
      if (e.size > 104857600) {
        this.$Message.error("选择/录制视频不能超过100M");
        return false;
      }
      return true;
    },
    handlevideosc(file) {
      this.videourl = file.content;
    },
    handleclicksc(file) {
      this.showvideoplay = true;
    },
    handleconfirpop() {
      if (this.videoList.length > 0) {
        this.carinfo.videofile = this.videoList[0].content;
      }
      //这里写提交后台代码
    },
    handleplay(item) {
      this.show = true;
      this.videoList = [];
      this.carinfo.ngEcoOpenNo = item.ngEcoOpenNo;
    } 
  }
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值