Packages

@surfjs/vue

Vue 3 composables for Surf โ€” local commands, real-time state, and Surf Live

@surfjs/vue

Vue 3 composables wrapping @surfjs/web. Register local command handlers, subscribe to Surf Live events, and sync state โ€” all with Vue reactivity.

Installation#

bash
npm install @surfjs/vue

@surfjs/web is included as a dependency โ€” no separate install needed.

useSurfCommands

Register local handlers that execute in the browser:

vue
<script setup>
import { useSurfCommands } from '@surfjs/vue'
ย 
useSurfCommands({
'theme.toggle': {
mode: 'local',
run: () => {
document.documentElement.classList.toggle('dark')
return { ok: true }
}
},
'canvas.clear': {
mode: 'local',
run: () => {
canvasStore.clear()
return { ok: true }
}
}
})
</script>

Handlers are registered on mount and automatically cleaned up on unmount via onUnmounted.

useSurfState

Reactive state synced from Surf Live events:

vue
<script setup>
import { useSurfState } from '@surfjs/vue'
ย 
const metrics = useSurfState('metrics', { users: 0, events: 0 })
</script>
ย 
<template>
<div>Online: {{ metrics.users }}</div>
</template>

Returns a Vue ref that auto-updates when the server sends surf:state or surf:patch events for the given key.

useSurf

Access the Surf context (requires SurfProvider):

vue
<script setup>
import { useSurf } from '@surfjs/vue'
ย 
const { execute, status, connected } = useSurf()
ย 
async function search(query) {
const result = await execute('search', { query })
console.log(result)
}
</script>

useSurfEvent

Subscribe to Surf Live events:

vue
<script setup>
import { useSurfEvent } from '@surfjs/vue'
ย 
useSurfEvent('notification', (data) => {
showToast(data.message)
})
</script>

Automatically cleans up on unmount.

SurfProvider

Manages WebSocket connection and provides context to child components:

vue
<template>
<SurfProvider url="wss://myapp.com/surf/ws" :endpoint="'https://myapp.com'">
<App />
</SurfProvider>
</template>
ย 
<script setup>
import { SurfProvider } from '@surfjs/vue'
</script>

| Prop | Type | Description | |------|------|-------------| | url | string | WebSocket URL for Surf Live | | endpoint | string? | Server URL for HTTP fallback | | auth | string? | Auth token | | channels | string[]? | Surf Live channels to subscribe to |

This site speaks Surf
AI agents can read and interact with this site through structured commands โ€” no scraping needed.
9 things agents can do
Search all documentation pagesGet the full documentation treeGet raw content of a doc pageList all @surfjs npm packagesGet details about a specific packageLatest release details+3 more
Surf ProtocolLearn more โ†’