封装小程序的Storage

817 阅读1分钟
class Storage {  
    static cache = {}; 
    constructor() {  } 
    static getStorage(key){   
       if (!this.cache[key]) {   
        this.cache[key] = wx.getStorageSync(key);  
       }    
       return this.cache[key];  }    
   static setStorage(key, val) {   
     wx.setStorageSync(key, val);   
      this.cache[key] = val;  }}
   export default Storage

页面使用Storage.getStorage('depoist_money_str')

Storage.setStorage('depoist_money_str','122344')