首页 > 代码库 > 微信小程序? 监听WebSocket关闭wx.onSocketClose(CALLBACK)

微信小程序? 监听WebSocket关闭wx.onSocketClose(CALLBACK)

微信小程序? 监听WebSocket关闭wx.onSocketClose(CALLBACK)

wx.onSocketClose(CALLBACK)

? 监听WebSocket关闭

wx.connectSocket({  url:"qkxue.net"});//注意这里有时序问题,//如果wx.connectSocket还没回调wx.onSocketOpen,而先调用wx.closeSocket,那么就做不到关闭WebSocket的目的//必须在WebSocket打开期间调用wx.closeSocket才能关闭wx.onSocketOpen(function(){  wx.closeSocket()})wx.onSocketClose(function(res){  console.log("WebSocket 已关闭!")})
稿源:勤快学QKXue.NET

微信小程序? 监听WebSocket关闭wx.onSocketClose(CALLBACK)