js导出功能 和 VUE项目下载文件,提示未找到文件

  一直忘,特此记下大致思路。


exportTable () {
      const origin = window.location.origin;
      const id = this.$route.params.id;
      window.open(`${origin}/pyxis-dict/api/dict/downLoadDict? 
      id=${id}`, '_self');
},

 

VUE项目下载文件,提示未找到文件(本地下载)

在 assets 等文件夹放置文件点击下载提示未找到文件的解决办法:

将要下载文件放到public 下面,a标签下载是相对于public

// 下载模板
    private downloadTemplate() {
        const url = './template/cartImport.xlsx';
        const name = 'cartImport.xlsx';
        var nowA =document.createElement('a');
        nowA.setAttribute('href',url);
        nowA.setAttribute('download',name);
        nowA.style.display= 'none';
        document.body.appendChild(nowA);
        nowA.click();
        document.body.removeChild(nowA);
    }
 
posted @ 2018-12-25 18:02  jiaqiq  阅读(1090)  评论(0编辑  收藏  举报