npm runserve 工作正常,突然它开始给出同样的错误。我无法理解它的根本原因以及它为什么不起作用。谁能建议如何解决这个问题?
"devDependencies": {
"@vue/cli-plugin-babel": "^4.2.0",
"@vue/cli-plugin-eslint": "^4.2.0",
"@vue/cli-plugin-router": "^4.2.0",
"@vue/cli-plugin-vuex": "^4.2.0",
"@vue/cli-service": "^4.2.0",
"@vue/eslint-config-prettier": "^6.0.0",
"babel-eslint": "^10.0.3",
"eslint": "^5.16.0",
"eslint-plugin-prettier": "^3.1.1",
"eslint-plugin-vue": "^6.1.2",
"prettier": "^1.19.1",
"sass": "^1.19.0",
"sass-loader": "^8.0.0",
"vue-cli-plugin-vuetify": "^2.0.5",
"vue-template-compiler": "^2.6.11",
"vuetify-loader": "^1.3.0"
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试服务器和客户端之间的套接字连接。我的服务器在 python 中。我为后端创建了一个 Fast API WebSocket,Vue.js 位于客户端。后端服务器正在按预期运行。但是每当我尝试加载前端时,我总是在控制台中收到此错误。我搜索了很多网站,但没有找到合适的解决方案。有人可以建议如何解决此错误以通过套接字连接前端和后端吗?
这是我的代码
var socket = new WebSocket("ws://localhost:8000")
socket.onmessage = function(e){
console.log(e.data)
}
socket.onerror = function(e){
console.log(e.data)
}
------------------------------backend--------------------------
@app.websocket("/ws")
async def websocket_endpoint(websocket: WebSocket):
await websocket.accept()
while True:
await websocket.send_text(f"Message text was: {data}")
Run Code Online (Sandbox Code Playgroud)