title: Taro.setStorageSync(key, data)
sidebar_label: setStorageSync
The synchronous version of Taro.setStorage.
Type
(key: string, data: any) => void
Parameters
| Property | Type | Description |
|---|---|---|
| key | string |
The specified key in the local cache |
| data | any |
Contents to be stored can only be native types, dates, and objects that can be serialized via JSON.stringify. |
Sample Code
Example 1
Taro.setStorage({key:"key",data:"value"})
Example 2
try {Taro.setStorageSync('key', 'value')} catch (e) { }
API Support
| API | WeChat Mini-Program | H5 | React Native |
|---|---|---|---|
| Taro.setStorageSync | ✔️ | ✔️ |
