微信小程序> 微信历史,微信小程序历史搜索历史的本地缓存和删除

微信历史,微信小程序历史搜索历史的本地缓存和删除

浏览量:677 时间: 来源:望月归乡
wxml:
viewclass='search_history'wx:if="{{isShow}}"viewclass='history_title'最近搜索/viewviewclass='history_item'wx:for="{{searchRecord}}"wx:key="{{index}}"wx:for-item="hisItem"textbindtap='search_his'data-his="{{hisItem}}"{{hisItem}}/text/viewviewclass='history_titleclear'bindtap='clear_search'清空搜索历史/view/viewwxss:
.search_history{height:auto;width:95%;position:relative;background-color:#fff;border-radius:5rpx;font-size:30rpx;color:#000;text-align:left;}.history_title{color:#999;text-align:left;padding:10rpx;}.history_item{display:inline-block;padding:10rpx15rpx;background-color:rgb(248,246,246);margin:10rpx;border-radius:10rpx;}.clear{display:inline-block;padding:10rpx15rpx;background-color:#66d7fa;color:#fff;margin:10rpx;border-radius:10rpx;}js:
//js用到的全局变量Page({data:{isShow:false,searchRecord:[],},//搜索的时候缓存到本地searchBox:function(e){letthat=this;letinputVal=e.detail.value.ip;letsearchRecord=this.data.searchRecord;if(inputVal==""){that.setData({ip:inputVal})return}else{if(searchRecord.length10){searchRecord.unshift(inputVal);}else{searchRecord.pop();searchRecord.unshift(inputVal);}//将历史记录数组整体储存到缓存中wx.setStorageSync('searchRecord',Array.from(newSet(searchRecord)));}that.setData({ip:e.detail.value.ip})},//缓存历史openHistorySearch:function(){letthat=this;that.setData({searchRecord:wx.getStorageSync('searchRecord')||[],//若无储存则为空})console.log(that.data.searchRecord);},//清空搜索历史clear_search:function(){letthat=this;wx.clearStorageSync('searhRecord')that.setData({searchRecord:[],isShow:false})},//点击历史搜索search_his:function(e){letthat=this;lethis=e.currentTarget.dataset.his;that.setData({ip:his,isShow:false});that.search_host();},})

版权声明

即速应用倡导尊重与保护知识产权。如发现本站文章存在版权问题,烦请提供版权疑问、身份证明、版权证明、联系方式等发邮件至197452366@qq.com ,我们将及时处理。本站文章仅作分享交流用途,作者观点不等同于即速应用观点。用户与作者的任何交易与本站无关,请知悉。

产品经理

手机 : 13312967497

擅长 : 小程序流量变现

扫码领取礼包

热门模板

  • 头条
  • 搜狐
  • 微博
  • 百家
  • 一点资讯
  • 知乎