🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
~~~ class KeywordModel{ getHistory(){ const words = wx.getStorageSync('q'); if(words){ return words }else{ return [] } } getHot(){ } addToHistory(keyword){ /* 将搜索的历史词汇添加到缓存中,如果缓存中存在则不添加 */ let words = this.getHistory(); const has = words.includes(keyword); if(!has){ /* 如果数组的长度大于10,则删除末尾的值*/ const length = words.length; if(length>10){ words.pop(); } words.unshift(keyword); wx.setStorageSync('q', words); } } } export {KeywordModel};