How to store data locally in Uniapp?

In uniapp, you can leverage the local storage API provided by uni-app to store data locally.

  1. uni.setStorageSync is used to save data in the local storage.
uni.setStorageSync('key', 'value');

key is the key used to store data, and value is the data to be stored.

  1. Retrieve data from local storage in the uni platform.
let value = uni.getStorageSync('key');

In this case, the “key” is the key used when storing the data previously.

  1. Clear the storage data from the uni module.
uni.removeStorageSync('key');

Key is the key of the data to be removed.

  1. Clear the synchronous storage of the uni.
uni.clearStorageSync();

In this way, you can store data locally in Uniapp using the methods mentioned above.

bannerAds