vue中a标签实现带header的下载excel文件

x33g5p2x  于2022-04-10 转载在 其他  
字(0.5k)|赞(0)|评价(0)|浏览(490)
import Cookie from 'js-cookie'

界面:

<a-button
          slot="extra"
          type="primary"
          @click="exportFile"
          ><a-icon type="download" />导出</a-button>

js方法

exportFile() {
          fetch('http://127.0.0.1:8765/course/exportCourse/33', {
              method: 'GET',
              headers: new Headers({
                  'Authorization': Cookie.get('Authorization') 
              }),
          })
         .then(res => res.blob())
         .then(data => {
              const blobUrl = window.URL.createObjectURL(data);
              const a = document.createElement('a');
              a.download = this.fileName+'.xlsx';
              a.href = blobUrl;
              a.click();
      });
      },

相关文章