网友问题:网友问题:
使用了vue-cli这个脚手架工具。在开发环境中如何配置跨域这个我懂。但是使用npm run build后,里面所有的ajax的跨域请求url都变成了根目录。
这样该如何解决部署的跨域问题?
使用了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
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.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

},
}

}
}以上就是小编整理的相关知识点,希望能够帮助到大家。