• 使用element UI elupload组件实现视频文件上传及上传进度显示方法总结


    实现效果:

    上传中:

     

    上传完成:

     

    代码:

    <el-form-item label="视频上传" prop="Video">
    <!-- action必选参数, 上传的地址 -->
    <el-upload class="avatar-uploader el-upload--text" :action="uploadUrl" :show-file-list="false" :on-success="handleVideoSuccess" :before-upload="beforeUploadVideo" :on-progress="uploadVideoProcess">
    <video v-if="videoForm.Video !='' && videoFlag == false" :src="videoForm.Video" class="avatar" controls="controls">您的浏览器不支持视频播放</video>
    <i v-else-if="videoForm.Video =='' && videoFlag == false" class="el-icon-plus avatar-uploader-icon"></i>
    <el-progress v-if="videoFlag == true" type="circle" :percentage="videoUploadPercent" style="margin-top:30px;"></el-progress>
    </el-upload>
    <P class="text">请保证视频格式正确,且不超过10M</P>
    </el-form-item>

    on-success:上传成功

    before-upload:验证

    on-progress:上传进度

    验证方法:验证视频格式和视频大小

    beforeUploadVideo(file) {
    const isLt10M = file.size / 1024 / 1024 < 10;
    if (['video/mp4', 'video/ogg', 'video/flv','video/avi','video/wmv','video/rmvb'].indexOf(file.type) == -1) {
    this.$message.error('请上传正确的视频格式');
    return false;
    }
    if (!isLt10M) {
    this.$message.error('上传视频大小不能超过10MB哦!');
    return false;
    }
    },
    上传进度显示:

    uploadVideoProcess(event, file, fileList){
    this.videoFlag = true;
    this.videoUploadPercent = file.percentage.toFixed(0);
    },
    file.percentage获取文件上传进度

    进度显示:

    <el-progress v-if="videoFlag == true" type="circle" :percentage="videoUploadPercent" style="margin-top:30px;"></el-progress>

    上传成功:

    handleVideoSuccess(res, file) { //获取上传图片地址
    this.videoFlag = false;
    this.videoUploadPercent = 0;
    if(res.status == 200){
    this.videoForm.videoUploadId = res.data.uploadId;
    this.videoForm.Video = res.data.uploadUrl;
    }else{
    this.$message.error('视频上传失败,请重新上传!');
    }
    },

    视频显示是在上传成功后后台返回视频地址,直接显示在页面中的。

  • 相关阅读:
    什么是shell
    shell种类
    centos7 安装JAVA (JDK 1.8) 并配置环境变量
    netcore liunx docker修改默认的Datetime format
    centos 7 安装 mysql 8.0.18
    centos 解决 mysql command not found
    centos 7 + Net Core 3.0 + Docker 配置说明(不含https)
    centos 7 安装golang1.13.5
    centos 7 安装git并配置ssh
    阿里云服务器 centos 7 安装postgresql 11
  • 原文地址:https://www.cnblogs.com/wuliujun521/p/15528138.html
Copyright © 2020-2023  润新知