上传文件检测文件类型及文件大小before-upload
beforeAvatarUpload(file) {
console.log(file.type)
const isLt2M = file.size / 1024 / 1024 < 10
const isJPG =
file.type === 'image/jpeg' ||
file.type === 'image/png' ||
file.type === 'image/jpg'
if (!isJPG) {
this.$message.error('上传图片只能是 JPG/PNG 格式!')
}
if (!isLt2M) {
this.$message.error('上传图片大小不能超过 10MB!')
}
return isLt2M && isJPG
}
获取上传视频播放时间,转换时分秒
// 获取视频时间
handleSuccess1(response, file, fileList) {
const video = document.createElement("video");
video.src = file.response;
video.addEventListener("loadedmetadata", () => {
var seconds = Math.floor(video.duration);
var hours = Math.floor(seconds / 3600);
var minutes = Math.floor((seconds - hours * 3600) / 60);
var remainingSeconds = seconds % 60;
// this.videotime = `${hours} 小时 ${minutes}分钟 ${remainingSeconds}秒`;
});
},