设置responseType为“blob”或“ arraybuffer”后无效

1,708 阅读1分钟

问题:vue-cropper裁剪报错

错误信息:exif-js-min.js?9b2e:94 Uncaught (in promise) TypeError: First argument to DataView constructor must be an ArrayBuffer

刚看到一脸懵逼,冷静下来看exif源码,发现是需要“arraybuffer”格式的返回数据,接着打印返回数据发现,“arraybuffer”并未生效。

image.png

经过一番折腾才发现是Mock这个罪魁祸首。

但是我是做的是一个后台模版又不能去掉Mock模块,咋整?

那就改改Mock的源码吧,先找到node_modules下的mockjs/dist/mock.js

解决办法:

方法一:

参考:segmentfault.com/q/101000001…

image.png

好吧,对我无效(exif中采用的原生请求),我调试了一下压根就没调用setRequestHeader,所以我只能自己看源码另求他法。

方法二:

image.png

需要设置responseType在调用open前(exif中是放在open后面的,导致调用open时拿不到responseType的值)。

image.png