<video
:src="currentUrl"
controls
:poster="this.dataList[0].imageShow"
:autoplay="false"
style="width: 100%; height: 100%;"
></video>
<canvas width="640" height="360" style="display: none;"></canvas>
import Vue from 'vue'
captureFrame(url, file) {
const video = document.createElement('video')
video.src = url
const canvas = document.createElement('canvas')
const ctx = canvas.getContext('2d')
video.onloadedmetadata = () => {
video.currentTime = 3//指定视频的低3秒
}
video.oncanplay = () => {
canvas.width = 1160
canvas.height = 570
ctx.drawImage(video, 0, 0, 1160, 570)
Vue.set(file, 'imageShow', canvas.toDataURL('image/png'))
}
},
this.currentUrl = require('@/assets/video.mp4')
this.captureFrame(this.currentUrl,this.dataList[0])