vue-socket.io跨域问题的解决方法

 

 

报错信息:

1 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.
2 vue-socketio.js?70bb:8 GET http://192.168.37.130:5050/socket.io/?EIO=3&transport=polling&t=N0oqNsW net::ERR_FAILED

解决办法:

 1 //vue.config.js
 2 
 3 module.exports = {
 4   devServer: {
 5     proxy: {
 6         '/socket.io': {
 7           target: 'http://192.168.37.130:5050',
 8           ws: true,
 9           changeOrigin: true
10         },
11         'sockjs-node': {
12           target: 'http://192.168.37.130:5050',
13           ws: false,
14           changeOrigin: true
15         },
16     }
17 
18   }
19 }

 

你可能感兴趣的:(vue-socket.io跨域问题的解决方法)