• vue下载后台传过来的乱码流的解决办法


    后台返回的乱码流

    解决办法:

    请求方式用的是axios,主要加关键的 {responseType: 'blob'}

    axios封装

    export function postDownload(url, data) {
      return new Promise((resolve, reject) => {
        instance.post(url,data,{responseType: 'blob'}).then(response => {
          resolve(response);
        }, err => {
          reject(err)
        })
      })
    }

    下载插件 npm install js-file-download -S

    运用:

    下载excel时,后台设置了excel标题,要去请求头去取,传输过程中文会有乱码的情况,需要编码下。

    let fileDownload = require("js-file-download");
    
    fileDownload(res.data,decodeURIComponent(res.headers['content-disposition'].split("=")[1]));
  • 相关阅读:
    # beta冲刺(2/7)
    # beta冲刺(1/7)
    福大软工 · 最终作业
    软工随笔纪实 《个人日志》
    beta答辩总结
    beta冲刺(6/7)
    (beta冲刺5/7)
    beta冲刺(4/7)
    beta冲刺(3/7)
    beta冲刺(2/7)
  • 原文地址:https://www.cnblogs.com/adbg/p/10579408.html
Copyright © 2020-2023  润新知