首页 > 语言 > JavaScript > 正文

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

2024-05-06 15:44:22
字体:
来源:转载
供稿:网友

网友问题:

使用了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.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    },  } }}

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

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表

图片精选