useBroadcastChannel
Reactive BroadcastChannel API.
Package: @vueuse/core
Category: Browser
Usage
import { useBroadcastChannel } from '@vueuse/core'
import { shallowRef } from 'vue'
const {
isSupported,
channel,
post,
close,
error,
isClosed,
} = useBroadcastChannel({ name: 'vueuse-demo-channel' })
const message = shallowRef('')
message.value = 'Hello, VueUse World!'
// Post the message to the broadcast channel:
post(message.value)
// Option to close the channel if you wish:
close()Options
| Option | Type | Default | Description |
|---|---|---|---|
| name | string |
- | The name of the channel. |
Returns
| Name | Type |
|---|---|
| isSupported | useSupported |
| channel | shallowRef<BroadcastChannel | undefined> |
| data | shallowRef |
| post | Ref |
| close | Ref |
| error | shallowRef<Event | null> |
| isClosed | shallowRef |