问题
项目上线后,遇到了接口请求的问题,提示Failed to execute 'readAsDataURL' on 'FileReader': parameter 1 is not of type 'Blob'.
debug后发现详情如下:
原来XMLHttpRequest是被重新定义了。开发环境下正常的情况应该是这样的:
解决
下面是适合我的项目的解决办法:项目是基于vue-element-admin二次开发的,然后在项目中全局搜索XMLHttpRequest,果然发现在mock中有redefine XMLHttpRequest的行为。
// for front mock
// please use it cautiously, it will redefine XMLHttpRequest,
// which will cause many of your third-party libraries to be invalidated(like progress event).
function mockXHR() {
...
}
不过发现vue-element-admin作者已经在main.js中说明了需要在正式环境中去除掉相关代码,唉,还是学习的不到位,疏忽了!
/**
* If you don't want to use mock-server
* you want to use MockJs for mock api
* you can execute: mockXHR()
*
* Currently MockJs will be used in the production environment,
* please remove it before going online ! ! !
*/
if (process.env.NODE_ENV === 'production') {
const { mockXHR } = require('../mock')
mockXHR()
}