vue+mockjs下载文件导致乱码问题

104 阅读1分钟

排查原因

项目中前期引入了 mockjs 进行模拟数据请求。导致请求结果被mock拦截,修改了返回数据类型。

打开node_modules>找到mockjs>找到dist>mockjs的8361行,代码如下:

if (!this.match) {
   this.custom.xhr.send(data)
   return
}

解决方法

代码如下:

// 原生 XHR
// if (!this.match) {
//     this.custom.xhr.send(data)
//     return
// }
// 处理响应类型
if (!this.match) {
        this.custom.xhr.responseType = this.responseType
        this.custom.xhr.send(data)
        return
}