vue3导出excel中文乱码怎么解决

前端 潘老师 5个月前 (12-08) 115 ℃ (0) 扫码查看

本文主要讲解关于vue3导出excel中文乱码怎么解决相关内容,让我们来一起学习下吧!

后端返回blob格式

excel中文乱码加上这个就解决了

{type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'}

完整代码

const exportExcelUserList = (params:any) =>
request({
  url: API.exportExcelUserList,//你的请求地址
  method: 'get',
  responseType: 'blob',
  params,//params是一个对象。get的对象传参方式
})
const exportExcel = () => {
    exportExcelUserList(queryParamas())  //接口地址
    .then((res:any) => {
      let blob = new Blob([res],{type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'});
      let url = window.URL.createObjectURL(blob); // 创建 url 并指向 blob
      let a = document.createElement("a");
      a.href = url;
      a.download = `会员列表.xlsx`;
      a.click();
    })
    .catch((error) => {
      reject(error.toString());
    });
};

以上就是关于vue3导出excel中文乱码怎么解决相关的全部内容,希望对你有帮助。欢迎持续关注潘子夜个人博客(www.panziye.com),学习愉快哦!


版权声明:本站文章,如无说明,均为本站原创,转载请注明文章来源。如有侵权,请联系博主删除。
本文链接:https://www.panziye.com/front/12277.html
喜欢 (0)
请潘老师喝杯Coffee吧!】
分享 (0)
用户头像
发表我的评论
取消评论
表情 贴图 签到 代码

Hi,您需要填写昵称和邮箱!

  • 昵称【必填】
  • 邮箱【必填】
  • 网址【可选】