vue-socket.io跨域问题有效解决方法-创新互联
网友问题:

使用了vue-cli这个脚手架工具。在开发环境中如何配置跨域这个我懂。但是使用npm run build后,里面所有的ajax的跨域请求url都变成了根目录。
这样该如何解决部署的跨域问题?
报错信息:
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
解决办法:
//vue.config.js
module.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
},
}
}
} 网站名称:vue-socket.io跨域问题有效解决方法-创新互联
当前地址:http://www.jxjierui.cn/article/dgeiod.html


咨询
建站咨询
