vueuse / vueuse

Collection of essential Vue Composition Utilities for Vue 2 and 3

Home Page:https://vueuse.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

useWebsocket in webworker:window in not defined

sy19971224 opened this issue · comments

Describe the bug

in work.js,i used useWebsocket,the socket connect successfully,but when i want to use the websocket
response data , an error message appears : window in not defined
here is my worker.js
import {useWebsocket} from @vueuse/core self.addEventlistener('message',(e) => { const {data} = useWebsocket(e.data.url,{ autoReconnect:{delay:3000}, onConnected:(ws) => { const sub = JSON.stringify({xxxx}) ws.send(sub) } }) // ----- error here : console.log(data) ---- })

Reproduction

none

System Info

npm:7.21.1
vue:2.7
vite:^3.1.3
vueuse/core:^7.5.3

Used Package Manager

npm

Validations

import {useWebsocket} from '@vueuse/core'
 self.addEventlistener('message',(e) => { 
 const {data} = useWebsocket(e.data.url,{ 
  autoReconnect:{delay:3000},
  onConnected:(ws) => { 
     const sub = JSON.stringify({xxxx}) 
     ws.send(sub) 
      } 
   }) 
   // ----- error here : console.log(data) ---- 
})