当前位置:   article > 正文

WebSocket connection to ‘ws://localhost:3000/ws‘ failed: Error in connection establishment: net::ERR

WebSocket connection to ‘ws://localhost:3000/ws‘ failed: Error in connection establishment: net::ERR

出现的错误情况:

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中进行下列的配置

  1. const { defineConfig } = require('@vue/cli-service')
  2. module.exports = defineConfig({
  3. transpileDependencies: true,
  4. lintOnSave: false, //关闭语法检查
  5. devServer:{
  6. host: '0.0.0.0',
  7. port:3000,
  8. client: {
  9. webSocketURL: 'ws://0.0.0.0:3000/ws',
  10. },
  11. headers: {
  12. 'Access-Control-Allow-Origin': '*',
  13. }
  14. }
  15. })

本文内容由网友自发贡献,转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号