<el-upload :on-change="uploadVideoChange"> <el-button size="small" type="primary"> <i class="el-icon-upload" />點擊上傳 </el-button> </el-upload>
uploadVideoChange (file, fileList) {
// 防止觸發兩次
if (file.status !== 'ready') return
const getVideoInfo = new Promise((resolve) => {
const videoElement = document.createElement("video");
videoElement.src = URL.createObjectURL(file.raw);
videoElement.addEventListener("loadedmetadata", function () {
resolve({
duration: videoElement.duration,
height: videoElement.videoHeight,
width: videoElement.videoWidth
});
});
});
getVideoInfo.then((videoInfo) => {
console.log(videoInfo);
})
}