useLocalStorage
Reactive localStorage.
- You can storage
Array
andPlainObject
.- You can use
localStorage.setItem
directly, it will effects and changes the localStorage item's value.- It will sync the localStorage item value when the page focus.
Usage
name:
type:
{
"value": null
}
<template>
<div>
<p>name: <input v-model="state.name" /></p>
<p>type: <input v-model="state.type" /></p>
<p><pre lang="json">{{JSON.stringify(state, null, 2)}}</pre></p>
</div>
</template>
<script lang="ts">
import { ref } from "vue";
import { useLocalStorage } from "vueposu";
export default {
setup() {
const state = useLocalStorage('useLocalStorage-demo-state', {
name: 'Tom',
type: 'Cat'
});
return {
state
}
},
};
</script>
Return
Property | Type | Description |
---|---|---|
itemValue | Ref<T> | the localStorage item's value |
Params
Property | Type | Required | Default | Description |
---|---|---|---|---|
key | string | true | - | the localStorage item's key name |
defaultValue | T | false | null | the defualt localStorage item's value |