useWebSocket 麻烦前端小哥丢点代码示例,不太会用哈。

useWebSocket 麻烦前端小哥丢点代码示例,不太会用哈。
1 HoseaDev Nov 29, 2023 1.文档。 2.GPT 。 |
3 lozzow Nov 29, 2023 |
4 LuoyeBug Nov 29, 2023 google 的 bard 可以回复 |
5 Puteulanus Nov 29, 2023 把下面的 source 给 ChatGPT 让它重写了文档和示例,你看能用不 https://chat.openai.com/share/1a3f76ba-40ab-48ae-be95-d3107234ae7a |
6 lx000377 Nov 29, 2023 |
7 tlerbao OP @lx000377 小哥 原生中 ws.onopen 里有一些操作,对应 useWebSockt 应该写在哪里? ``` ws = new WebSocket(url); ws.Onopen= function () { m_isCOnnectWS= true; unload(); sendInitMsg(); //初始化 sendGetPath(); //获取电脑中的路径 m_closed = false; }; ``` |
8 Dragonphy Nov 30, 2023 GPT 不会你可以把源码实现塞给他 |
9 jawilx Nov 30, 2023 文档不是写的挺清楚吗 |
10 jawilx Nov 30, 2023 export interface UseWebSocketReturn<T> { /** * Reference to the latest data received via the websocket, * can be watched to respond to incoming messages */ data: Ref<T | null> /** * The current websocket status, can be only one of: * 'OPEN', 'CONNECTING', 'CLOSED' */ status: Ref<WebSocketStatus> /** * Closes the websocket connection gracefully. */ close: WebSocket['close'] /** * Reopen the websocket connection. * If there the current one is active, will close it before opening a new one. */ open: Fn /** * Sends data through the websocket connection. * * @param data * @param useBuffer when the socket is not yet open, store the data into the buffer and sent them one connected. Default to true. */ send: (data: string | ArrayBuffer | Blob, useBuffer?: boolean) => boolean /** * Reference to the WebSocket instance. */ ws: Ref<WebSocket | undefined> } |