Agontuk / vue-cropperjs

A Vue wrapper component for cropperjs https://github.com/fengyuanchen/cropperjs
MIT License
934 stars 225 forks source link

XMLHttpRequest with responseType set to "arraybuffer" 报错问题 #70

Open yjp1105286534 opened 4 years ago

yjp1105286534 commented 4 years ago

当我打包到生产环境运行时 浏览器提示我原因XMLHttpRequest在同步请求下 responseType不允许被设置,报错 解决办法 dist/croppper.js 注释掉 // xhr.responseType = 'arraybuffer'; xhr.withCredentials = element.crossOrigin === 'use-credentials'; xhr.send(); 然后再这个方法里加上 stringToArrayBuffer方法 xhr.onload = function () { _this.read(stringToArrayBuffer(xhr.response)); };

function stringToArrayBuffer(str) { var buf = new ArrayBuffer(str.length); var bufView = new Uint8Array(buf);

for (var i=0, strLen=str.length; i<strLen; i++) {
    bufView[i] = str.charCodeAt(i);
}

return buf;

}