localStorage
Start from API_LEVEL
2.0
. Please refer to API_LEVEL.
Locally stored key-value pairs, data cleared after Mini Program uninstallation.
info
permission code: device:os.local_storage
Methods
setItem
Get sleep information
setItem(key: string, value: any): void
getItem
Read the data, specify the default value defaultValue
, and return defaultValue
if the value on the specified key
is not retrieved.
getItem(key: string, defaultValue?: any): void
removeItem
Delete the data of the specified key
removeItem(key: string): void
clear
Clear all data in localStorage
clear(): void
Example
import { localStorage } from '@zos/storage'
localStorage.setItem('test', 'test value')
const val = localStorage.getItem('test')
const defaultValue = localStorage.getItem('none_key', 'defaultValue')
localStorage.removeItem('test')
localStorage.clear()