2022-05-16 浏览器控制台sockjs-node/info报错

浏览器http://localhost:8080/...控制台一直持续报错,Access to XMLHttpRequest at 'http://192.168.0.121:8080/sockjs-node/info?t=1630725706587' from origin 'http://localhost' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.和sockjs.js?9be2:1609 GET http://192.168.0.121:8080/sockjs-node/info?t=1630725706587 net::ERR_FAILED。

我这种强迫症是没有办法接受的。百度了国内的一些解决方案,是居然是修改源码?-_______-!!!。

Google了一下,老外的大部分办法是修改vue-config.js增加devServer,我看了一下https://webpack.js.org/configuration/dev-server/官方说明,个人认为最好的方案是
修改启动参数,这样不影响本地版本提交到服务器。具体方法是package.json将scripts里的serve增加--host localhost参数。

{
  //...
  "scripts": {
    "serve": "vue-cli-service serve --host localhost",
    "build": "vue-cli-service build",
    "lint": "vue-cli-service lint"
  },
  //...
}

你可能感兴趣的:(2022-05-16 浏览器控制台sockjs-node/info报错)