利用ajax上傳url來獲取文件信息
testImgVidoe(imgurl) {
this.$ajax.defaults.withCredentials = false; //關閉發(fā)送cookie
return new Promise((resolve, reject) => {
this.$ajax
.get(imgurl, {
responseType: 'blob',
})
.then(
res => {
this.$ajax.defaults.withCredentials = true; //開啟發(fā)送cookie
resolve(res.type.split('/')[0]); //獲取文件類型 如:video 、image
},
error => {
this.$ajax.defaults.withCredentials = true; //開啟發(fā)送cookie
// console.log(error);
reject('地址不合法');
}
);
});
},
使用
this.testImgVidoe(url)
.then(res => {
console.log(res);
//返回文件類型
})
.catch(error => {
console.log(error);
});```