title: Taro.setStorageSync(key, data)

sidebar_label: setStorageSync

The synchronous version of Taro.setStorage.

Reference

Type

  1. (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

  1. Taro.setStorage({
  2. key:"key",
  3. data:"value"
  4. })

Example 2

  1. try {
  2. Taro.setStorageSync('key', 'value')
  3. } catch (e) { }

API Support

API WeChat Mini-Program H5 React Native
Taro.setStorageSync ✔️ ✔️