出现的错误情况:
vue创建项目打开页面后可以运行正常,就是控制台一直隔几秒报websocket的connection错误
错误如下:
WebSocket connection to 'ws://localhost:3000/ws' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED
WebSocketClient | @ | WebSocketClient.js?5586:16 | |
initSocket | @ | socket.js?d6e0:24 | |
eval | @ | socket.js?d6e0:48 |
解决方法:
在vue.config.js中进行下列的配置
const { defineConfig } = require('@vue/cli-service')module.exports = defineConfig({ transpileDependencies: true, lintOnSave: false, //关闭语法检查 devServer:{ host: '0.0.0.0', port:3000, client: { webSocketURL: 'ws://0.0.0.0:3000/ws', }, headers: { 'Access-Control-Allow-Origin': '*', } }})
来源地址:https://blog.csdn.net/weixin_63689594/article/details/128894192