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();},})

TAG标签: 微信小程序小程序微信历史

http://www.xiaochengxub.com/read-108062.html