vue如何实现input file如何实现预览效果?

我用的video的方式实现的

html

<label id="labelr" class="pop_file file_cont" for="pop_video">
    <div class="pfevi">
        <div><i class="iconfont icon-tianjia1"></i></div>
        <div>点击上传视频</div>
    </div>
    <video id="videoId"></video>
    <input style="display: none;" id="pop_video" type="file" accept="audio/mp4,video/mp4" v-on:change="uploadFile($event,'2')" name="fileTrans" ref="file" value="" />
</label>

css

.pop_file {
    width: 370px;
    height: 188px;
    margin-bottom: 30px;
    display: block;
    font-size: 14px;
    font-family: MicrosoftYaHei;
    color: rgba(153, 153, 153, 1);
    background: rgba(247, 247, 247, 1);
    position: relative;
}
.pop_file video {
    width: 100%;
    height: auto;
    position: absolute;
    top: 0;
    left: 0;
    z-index: 100;
}

js

uploadFile: function(ev, typer) {
    var that = this;
    var filesId = document.getElementById('pop_video');
    var videoId = document.getElementById('videoId');
    var url = getFileURL(filesId.files[0]); //把当前的 files[0] 传进去
    if(url) {
        videoId.src = url;
    }
    function getFileURL(file) {
        var getUrl = null;
        if(window.createObjectURL != undefined) { // basic
            getUrl = window.createObjectURL(file);
        } else if(window.URL != undefined) { // mozilla(firefox)
            getUrl = window.URL.createObjectURL(file);
        } else if(window.webkitURL != undefined) { // webkit or chrome
            getUrl = window.webkitURL.createObjectURL(file);
        }
        return getUrl;
    }
    var duration = videoId.duration;
    if(Math.floor(duration) > 60) {
        that.$layer.msg('视频不能大于60秒');
    }
}

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值