網(wǎng)友問題:
使用了vue-cli這個腳手架工具。在開發(fā)環(huán)境中如何配置跨域這個我懂。但是使用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 }, } } }