Vue-socket.io cross-domain problem effective solution

User Question: Use the Vue-CLI this scaffolding tool. How to configure cross-domain this in the development environment. However, after using NPM Run Build, the cross-domain request URL of the Ajax inside has become a root directory.

How to solve the deployed cross-domain problem?


An error message:

Access to XmlhttpRequest at ‘http://192.168.37.130:5050/socket.io/?eio=3&transport = polling & t = N0oqNsW ‘from origin’ http: // localhost: 8080 ‘has been blocked by CORS policy: No’ Access-Control-Allow-Origin ‘header is present on the requested resource

. Vue-socketio.js? 70bb: 8 get http://192.168.37.130:5050/socket.io/?eio=3&transport=polling&t=n0oqnsw net :: err_failed


Solution :

// vue.config.jsmodule.exports = {DevServer: {proxy: {‘/socket.io’: {target: ‘http: / / 192.168.37.130:5050 ‘, ws: true, changeorigin: true},’ sockjs-node ‘: {Target: ‘http://192.168.37.130:5050’, ws: false, changeorigin: true},}}}

The above is TUMI Yun Xiaobian finishing Related knowledge points, I hope to help everyone.
© Copyright Notice
THE END
Just support it if you like
like0
share
comment Grab the couch

Please log in to comment