使用element UI el-upload组件上传图片或视频时获取尺寸

const isSize = new Promise((resolve,reject)=>{
	if(type == '图片') {
	    //上传文件为图片类型
	    let img = new Image()
	    img.onload = function(){
		    resolve(img)
	    }
	    img.src = URL.createObjectURL(file.raw)
	}else {
		//上传文件为视频类型
		var videoUrl = URL.createObjectURL(file.raw)
		var videoObj = document.createElement("video")
		videoObj.onloadedmetadata = function (evt) {
		    URL.revokeObjectURL(videoUrl);
		    videoObj.width = videoObj.videoWidth
		    videoObj.height = videoObj.videoHeight
		    // 执行上传的方法,获取外网路径,上传进度等
		    resolve(videoObj)
	    }
		videoObj.src = videoUrl
		videoObj.load()
	}
}).then((res)=>{
	let width = res.width
	let height = res.height	
},(err)=>{
	return Promise.reject();
})

 

你可能感兴趣的:(前端,javascript,vue.js)