diff --git a/packages/core/useWebSocket/index.ts b/packages/core/useWebSocket/index.ts index 84eb48c0fe4..48e68da7d12 100644 --- a/packages/core/useWebSocket/index.ts +++ b/packages/core/useWebSocket/index.ts @@ -203,10 +203,12 @@ export function useWebSocket( } const _init = () => { + if (explicitlyClosed) + return + const ws = new WebSocket(url, protocols) wsRef.value = ws status.value = 'CONNECTING' - explicitlyClosed = false ws.onopen = () => { status.value = 'OPEN' @@ -289,6 +291,7 @@ export function useWebSocket( const open = () => { close() + explicitlyClosed = false retried = 0 _init() }