出现的错误情况:
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 |
文章来源:https://www.toymoban.com/news/detail-537831.html
解决方法:
在vue.config.js中进行下列的配置文章来源地址https://www.toymoban.com/news/detail-537831.html
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': '*',
}
}
})
到了这里,关于WebSocket connection to ‘ws://localhost:3000/ws‘ failed: Error in connection establishment: net::ERR的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!