封装下载文件的方法:
1:
export const downLoadFile = model => {
//下载文件
let aTag = document.createElement("a");
aTag.download = model.filename;
aTag.href = model.filepath; //URL.createObjectURL(blob);
aTag.target = "_blank";
//aTag.type="application/x-download"
document.body.appendChild(aTag);
aTag.click();
aTag.remove();
};
.then((res) => {
if (res) {
this.pathList.forEach((item) => {
downLoadFile(item);
this.$Message.success("下载素材成功");
});
}
});
处理代码段: pathList: 表示需要上传的路径。 循环每一个路径。 调用download 方法。 item 方法代表每一个对象, 对应每一个model 对象。 调用model事件中的filepath 字段。