用过 VueUse 中 useWebSocket 的前端小哥麻烦丢点代码示例 - V2EX
请不要在回答技术问题时复制粘贴 AI 生成的内容
tlerbao

用过 VueUse 中 useWebSocket 的前端小哥麻烦丢点代码示例

  •  
  •   tlerbao Nov 29, 2023 2628 views
    This topic created in 903 days ago, the information mentioned may be changed or developed.

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

    10 replies    2023-11-30 09:30:39 +08:00
    HoseaDev
        1
    HoseaDev  
       Nov 29, 2023
    1.文档。
    2.GPT 。
    tlerbao
        2
    tlerbao  
    OP
       Nov 29, 2023
    @HoseaDv 文档那是一个简单,GPT 表示不会或者信息过时了。
    LuoyeBug
        4
    LuoyeBug  
       Nov 29, 2023
    google 的 bard 可以回复
    Puteulanus
        5
    Puteulanus  
       Nov 29, 2023
    把下面的 source 给 ChatGPT 让它重写了文档和示例,你看能用不 https://chat.openai.com/share/1a3f76ba-40ab-48ae-be95-d3107234ae7a
    lx000377
        6
    lx000377  
       Nov 29, 2023
    写的贼烂...
    tlerbao
        7
    tlerbao  
    OP
       Nov 29, 2023
    @lx000377
    小哥 原生中 ws.onopen 里有一些操作,对应 useWebSockt 应该写在哪里?
    ```
    ws = new WebSocket(url);
    ws.Onopen= function () {
    m_isCOnnectWS= true;
    unload();
    sendInitMsg(); //初始化
    sendGetPath(); //获取电脑中的路径
    m_closed = false;
    };
    ```
    Dragonphy
        8
    Dragonphy  
       Nov 30, 2023
    GPT 不会你可以把源码实现塞给他
    jawilx
        9
    jawilx  
       Nov 30, 2023
    文档不是写的挺清楚吗
    jawilx
        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>
    }
    About     Help     Advertise     Blog     API     FAQ     Solana     5677 Online   Highest 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 68ms UTC 06:26 PVG 14:26 LAX 23:26 JFK 02:26
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86