The vue project uses elementui to upload components and reports an error after packaging. t.upload.addEventListener is not a function

background

There is no problem in the local development environment test, but the deployment server reports an error after packaging.
insert image description here
This problem is caused by mockjs changing the XMLHttpRequest object in axios.
Try the three solutions

Modify method 1

Add about line 8312 of the node_modules/mockjs/dist/mock.js file

MockXMLHttpRequest.prototype.upload = xhr.upload;

Add a native xhr.upload method to the MockXMLHttpRequest object.
insert image description here

Modify method 2

Also modify line 216 of node_modules/mockjs/src/xhr/xhr.js, about line 8312 of node_modules/mockjs/dist/mock.js file
Add

MockXMLHttpRequest.prototype.upload = xhr.upload;

Add a native xhr.upload method to the MockXMLHttpRequest object.

Modify method 3

Uninstall mockjs and delete related codes

npm uninstall mockjs 

view.config.js
insert image description here

Comment this code
src/main.js
insert image description here

comment this code

Guess you like

Origin blog.csdn.net/lhkuxia/article/details/127554848