说明:下载图片和文档资料是两种不同的方式,所以需要先判断下载的是图片还是word,excel等文件资料
目录
window.location.href = '文件路径';
handleClick(item) {
let fileSrc = `../../../data/${item.filepath}/${item.xzfilename}`;
let filename = item.filename;
let imgtype = ['png','jpg','jpeg','PNG','JPG','JPEG'];
if(imgtype.indexOf(item.filename.split('.')[1]) != -1){
debugger;
//图片类型下载方式
this.saveFileImg(fileSrc,filename);
}else{
debugger;
//文档类型
window.location.href = fileSrc;
}
},
saveFileImg(data,filename){
var save_link = document.createElementNS('http://www.w3.org/1999/xhtml', 'a');
save_link.href = data;
save_link.download = filename;
var event = document.createEvent('MouseEvents');
event.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
save_link.dispatchEvent(event);
},