vue+java导出word文件 前端部分

导出方法

<el-button type="primary" style="margin-top:20px" @click="exWord">
      打印
    </el-button>
exWord() {
      test(this.goods.id).then(res => {
        console.log(res)
        // type 为需要导出的文件类型,此处为xls表格类型
        const blob = new Blob([res], { type: 'application/msword;charset=utf-8' });
        // 兼容不同浏览器的URL对象
        const url = window.URL || window.webkitURL || window.moxURL;
        // 创建下载链接
        const downloadHref = url.createObjectURL(blob);
        // 创建a标签并为其添加属性
        let downloadLink = document.createElement('a');
        downloadLink.target = '_blank';
        downloadLink.href = downloadHref;
        // filename = filename ? filename : new Date().getTime();
        downloadLink.download = '木材统计.doc';
        // 触发点击事件执行下载
        downloadLink.click();
      })
    },

 

参考:https://www.136.la/shida/show-160383.html

posted @ 2022-03-17 17:04  你猜我为啥秃头  阅读(477)  评论(0)    收藏  举报