Skip to content

TerryYoung518/vue3-localstorage-sync

Repository files navigation

vue3-localstorage-sync npm

English|中文

This project is based on Vue3's watch method and browser's native localStorage, achieving data synchronization between same-origin pages by listening to the storage event of the window object.

Installation

npm i vue3-localstorage-sync

Usage

Import useBind method from vue3-localstorage-sync:

import { useBind } from 'vue3-localstorage-sync'

Create a ref or reactive object and pass in a unique key as the binding basis. Optionally, use the returned reactive object. The data will be stored in the browser's localStorage under the provided key.

// Method 1
const count = useBind(ref(0), 'count');

// Method 2
const count = ref(0);
useBind(count, 'count')

About

A simple utility package that synchronizes reactive data between localStorage and different pages in a Vue 3 application.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published