业务需求,部分数据需要mock,其他模块存在文件下载导出功能,后端返回为二进制格式 当mock遇到blob时,报
Failed to execute 'readAsText' on 'FileReader': parameter 1 is not of type 'Blob'
是因为mockjs会拦截responseType
解决方案1:修改源码,地址node_modules -> mockjs -> dist -> mockjs -> 8363行新增一行代码
// 原生 XHR
if (!this.match) {
+ this.custom.xhr.responseType = this.responseType || ''
this.custom.xhr.send(data)
return
}
需要在xhr.send 上方
重启项目 -> 完成
弊端
切换分支等都需要修改源码,且项目开发人员都需要修改
解决方案2:按方法1修改,把mockjs挪到src目录下,main.
经测试,打包部署正常!
谢谢大家!