Skip to main content
Version: 3.x

Taro.setStorageSync(key, data)

The synchronous version of Taro.setStorage.

Reference

Type​

(key: string, data: any) => void

Parameters​

PropertyTypeDescription
keystringThe specified key in the local cache
dataanyContents 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​

APIWeChat Mini-ProgramH5React Native
Taro.setStorageSync✔️✔️