fn
useTabLeader
v0.0.13testeddemoElects a single leader tab using the Web Locks API. Only one tab at a time holds the lock for a given key. When the leader tab closes or the scope is disposed, another tab automatically becomes the leader.
Example
ts
const { isLeader } = useTabLeader('payment-polling');
watchEffect(() => {
if (isLeader.value) {
// Only this tab performs polling
startPolling();
} else {
stopPolling();
}
});Demo
Loading demo…
Signature
ts
export function useTabLeader(key: string, options: UseTabLeaderOptions ={ ... }Parameters
| Parameter | Type | Description |
|---|---|---|
key | string | A unique lock name identifying the leader group |
options? | UseTabLeaderOptions | Options |
Returns
UseTabLeaderReturnLeader state and controls