Vue项目下载项目本地文件

axios.get('file/template.xlsx', {   //静态资源文件夹public
        responseType: 'blob',
      }).then(response => {
        const url = window.URL.createObjectURL(new Blob([response.data]));
        const link = document.createElement('a');
        let fname = '模板.xlsx';
        link.href = url;
        link.setAttribute('download', fname);
        document.body.appendChild(link);
        link.click();
      }).catch(error => {
        console.log('error:' + JSON.stringify(error))
      });

 

posted @ 2023-06-15 09:38  wxxwjef  阅读(377)  评论(0)    收藏  举报