How to store data locally in Uniapp?
In uniapp, you can leverage the local storage API provided by uni-app to store data locally.
- 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.
- 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.
- Clear the storage data from the uni module.
uni.removeStorageSync('key');
Key is the key of the data to be removed.
- Clear the synchronous storage of the uni.
uni.clearStorageSync();
In this way, you can store data locally in Uniapp using the methods mentioned above.