Skip to content

Vue API ​

ts
import {
  createFetchPlugin,
  provideFetchClient,
  useFetch,
  useSse,
  fetchClientKey,
} from 'tanstack-fetch/vue'
ExportRole
createFetchPlugin(opts)app.use(...) / Nuxt plugin — provides the client
provideFetchClient(api)provide in a parent setup for child useFetch
useFetch()Inject the shared client
useSse(path, options)Vue SSE helper (needs SSE client)
fetchClientKeyInjection key (advanced)

Nuxt already ships a core useFetch. Rename on import when needed:

ts
import { useFetch as useFetchClient } from 'tanstack-fetch/vue'

useSse result ​

FieldType
dataRef — last message payload
eventRef — last full SSE event
errorRef — last error
statusRef<'connecting' | 'connected' | 'disconnected' | 'error'>
closeStop the stream

useSse options ​

OptionRole
clientSSE client from tanstack-fetch/sse (preferred — no plugin)
enabledWhen false, stays disconnected

Example (no plugin) ​

vue
<script setup lang="ts">
import { createFetch } from 'tanstack-fetch/sse'
import { useSse } from 'tanstack-fetch/vue'

const api = createFetch({
  plugins: ['sse-resume'],
  getToken: () => localStorage.getItem('access_token'),
})

const { data, status, error, close } = useSse<{ id: string }>('/orders/stream', {
  client: api,
})
</script>

<template>
  <p v-if="status === 'connecting'">Connecting…</p>
  <p v-else-if="status === 'error'">{{ error?.message }}</p>
  <div v-else>
    <p>{{ status }}</p>
    <pre>{{ data }}</pre>
    <button type="button" @click="close">Disconnect</button>
  </div>
</template>

Guide: Vue & Nuxt · SSE

MIT Licensed · Created by Mohammad Garmabi · Not an official TanStack package