下载本地文件核心代码:
importTemplate() {
// this.download('plk/material/importTemplate', {
// }, `物料导入模板.xlsx`)
// 创建一个<a></a>标签
const a = document.createElement('a');
a.href = '/replace.xlsx';
a.download = 'replace.xlsx';
// console.log(a.href);
// 障眼法藏起来a标签
a.style.display = 'none';
// 将a标签追加到文档对象中
document.body.appendChild(a);
// 模拟点击了<a>标签,会触发<a>标签的href的读取,浏览器就会自动下载了
a.click();
// 一次性的,用完就删除a标签
a.remove();
},
注意:要下载的文件需要放在public文件夹里面