Skip to main content
You are viewing Pre-Alpha documentation.
Vuetify0 Logo
Mode
Accessibility
Vuetify

useStorage

The useStorage composable provides reactive storage management with support for multiple storage backends (localStorage, sessionStorage, memory). Built with an adapter pattern for flexibility, it automatically serializes values, manages reactive refs, and provides SSR-safe operations.

Intermediate99% coverageJan 11, 2026

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:

UseStorage
<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>

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

API Reference

The following API details are for the useStorage composable.

Functions

createStorage

(options?: StorageOptions) => E

Creates a new storage instance.

createStorageContext

(_options?: StorageContextOptions) => ContextTrinity<E>

createStoragePlugin

(_options?: StoragePluginOptions) => any

Creates a new storage plugin.

useStorage

(namespace?: string) => E

Returns the current storage instance.

Options

adapter

StorageAdapter

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

prefix

string

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

serializer

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

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

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+/