Skip to main content
Vuetify0 is now in alpha!
Vuetify0 Logo
Theme
Mode
Palettes
Accessibility
Vuetify One
Sign in to Vuetify One

Access premium tools across the Vuetify ecosystem — Bin, Play, Studio, and more.

Not a subscriber? See what's included

useStorage


IntermediateApr 5, 2026

Reactive storage with automatic serialization, caching, and SSR-safe operations.

Installation

Install the Storage plugin in your app’s entry point:

main.ts
import { createApp } from 'vue'
import { createStoragePlugin } from '@vuetify/v0'
import App from './App.vue'

const app = createApp(App)

app.use(createStoragePlugin())

app.mount('#app')

Usage

Once the plugin is installed, use the useStorage composable in any component:

vue
<script setup lang="ts">
  import { useStorage } from '@vuetify/v0'

  const storage = useStorage()

  // Get a reactive ref for a storage key
  const username = storage.get('username', 'Guest')

  // Update the value (automatically persists to storage)
  function updateUsername(name: string) {
    username.value = name
  }
</script>

<template>
  <div>
    <h1>Welcome, {{ username }}!</h1>
    <input v-model="username" placeholder="Enter your name" />
  </div>
</template>

Standalone Usage

Use createStorage directly without the plugin system for standalone or module-level caching:

ts
import { createStorage } from '@vuetify/v0'

const storage = createStorage({ prefix: 'myapp:' })

storage.set('theme', 'dark')

const theme = storage.get('theme', 'light')

console.log(theme.value) // 'dark'

TTL (Time-to-Live)

Set a ttl option (in milliseconds) to automatically expire cached entries. Expired entries return the default value on get() and are removed from storage.

ts
import { createStorage } from '@vuetify/v0'

// Cache expires after 5 minutes
const cache = createStorage({
  prefix: 'api-cache:',
  ttl: 5 * 60 * 1000,
})

// Store fetched data — automatically timestamped
cache.set('users', await fetchUsers())

// Later reads return the default if expired
const users = cache.get('users', [])
Tip

How TTL works When ttl is set, values are internally wrapped as { __ttl, __v, __t } with a timestamp. On get(), if the entry is older than the TTL, it is treated as absent and removed from storage. Non-TTL entries stored previously are read normally.

Adapters

Adapters let you swap the underlying storage backend without changing your application code.

AdapterImportDescription
localStorageBrowser localStorage (default in browser)
sessionStorageBrowser sessionStorage
MemoryAdapter@vuetify/v0/storage/adapters/memoryIn-memory storage (default in SSR)

Architecture

useStorage uses the plugin pattern with storage adapters:

Storage Plugin

Use controls to zoom and pan. Click outside or press Escape to close.

Storage Plugin

Reactivity

The get() method returns reactive refs that sync with storage automatically.

PropertyReactiveNotes
get() return valueReturns Ref<T> synced with storage
has()Returns boolean — checks if key exists (TTL-aware)
Tip

Auto-persistence Refs returned by get() are watched with { deep: true }. Any changes to the ref value automatically persist to storage.

Tip

Empty strings are preserved get() uses nullish coalescing (??) internally, so an empty string '' is a valid stored value — it is never treated as absent or replaced by the default. Only null and undefined trigger the default.

Examples

Persistent Settings

A settings panel that survives page refreshes using useStorage with a memory adapter, showing reactive get() refs with deep-watch auto-persistence.

0
Item 1

Keys: count, name, theme, items

has("count"): true

API Reference

The following API details are for the useStorage composable.

Functions

createStorage

(options?: StorageOptions) => E

Creates a new storage instance.

createStorageContext

<_E>(_options?: StorageContextOptions | undefined) => ContextTrinity<_E>

createStoragePlugin

(_options?: StorageContextOptions | undefined) => Plugin

useStorage

<_E>(namespace?: string) => _E

Options

adapter

StorageAdapter | undefined

The storage adapter to use. Defaults to localStorage in browser, MemoryAdapter otherwise

prefix

string | undefined

The prefix to use for all storage keys. Defaults to 'v0:'

serializer

{ read: (value: string) => unknown; write: (value: unknown) => string; } | undefined

Custom serializer for reading and writing values. Defaults to JSON.parse/stringify

ttl

number | undefined

Time-to-live in milliseconds. When set, expired entries return the default value on `get()` and `set()` automatically timestamps entries.

Methods

has

(key: string) => boolean

Check if a key exists in storage

get

<T>(key: string, defaultValue?: T) => Ref<T>

Get a reactive ref for a storage key

set

<T>(key: string, value: T) => void

Set a value for a storage key

remove

(key: string) => void

Remove a key from storage

clear

() => void

Clear all keys from storage

Was this page helpful?

© 2016-1970 Vuetify, LLC
Ctrl+/