我正在使用flask-socket在python中编写一个简单的flask应用程序。在控制台上,我面临:
“ [错误]参考错误:找不到变量:套接字”
和
“ ReferenceError:找不到变量:必需”
我附上了可能相关的代码片段。我将不胜感激。
document.addEventListener('DOMContentLoaded', () => {
//connect to websocket
var io = require('/Users/august/Desktop/project2/venv/lib/python3.7/site-packages/socketio');
var socket = io.connect(location.protocol + '//' + document.domain + ':' + location.port);
//when connected, configure buttons
socket.on('connect', () => {
// button should emit 'send message' event
document.querySelector("#submit-message").onclick = () => {
const message = document.querySelector("#message").value;
socket.emit('send message', {"message": message});
};
});
});