useWebSocket 麻烦前端小哥丢点代码示例,不太会用哈。
1
HoseaDev 364 天前
1.文档。
2.GPT 。 |
4
webluoye 364 天前
google 的 bard 可以回复
|
5
Puteulanus 364 天前
把下面的 source 给 ChatGPT 让它重写了文档和示例,你看能用不 https://chat.openai.com/share/1a3f76ba-40ab-48ae-be95-d3107234ae7a
|
6
lx000377 364 天前
|
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 363 天前
GPT 不会你可以把源码实现塞给他
|
9
xujiahui 363 天前
文档不是写的挺清楚吗
|
10
xujiahui 363 天前
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> } |