12345678910111213141516171819202122232425 |
- import config from "../model/config"
- export default {
- getStorage() {
- const res = wx.getStorageSync(config.NAMESPACE);
- return JSON.parse(res || "{}");
- },
- setItem(key, val) {
- const storage = this.getStorage();
- storage[key] = val;
- wx.setStorageSync(config.NAMESPACE, JSON.stringify(storage))
- },
- getItem(key) {
- const storage = this.getStorage();
- return storage[key];
- },
- clearItem(key) {
- const storage = this.getStorage();
- delete storage[key]
- wx.setStorageSync(config.NAMESPACE, JSON.stringify(storage))
- },
- clearAll() {
- wx.removeStorageSync(config.NAMESPACE)
- }
- }
|