const { ws, send, websocketOpen, data } = useWebSocket(
url,
{
reconnectCount: 5,
heartMessage: 'ping',
autoClose: true,
onMessage(ws, e) {
console.log('数据接收');
},
onOpen: () => {
console.log('链接成功');
},
onError: () => {
console.log('链接失败');
},
onClose: () => {
console.log('连接关闭');
},
onFailed: () => {
console.log('达到重连次数(5),重连失败');
}
}
);
websocket 通信,支持心跳检测、断线重连机制