//index.js //获取应用实例 var app = getApp() Page({ data: { selectHide: false, inputValue: '', getSearch: [], modalHidden: true, searching:false }, onLoad: function () { }, onShow: function () { var getSearch = wx.getStorageSync('searchData'); this.setData({ getSearch: getSearch, inputValue: '' }) console.log('search is onshow', getSearch) }, /*-------------------- 交互----------*/ // 设置缓存 setSearchStorage: function () { let data; let localStorageValue = []; if (this.data.inputValue != '') { //调用API从本地缓存中获取数据 var searchData = wx.getStorageSync('searchData') || [] searchData.push(this.data.inputValue) wx.setStorageSync('searchData', searchData) this.setData({ getSearch: searchData, }) } else { console.log('空白') } }, // 加载数据 loadData(){ }, /*-------------------- 交互----------*/ // 返回 back: function () { wx.navigateBack({ }) }, // 清除输入框 clearInput: function () { this.setData({ inputValue: '' }) }, // 输入完成 inputEnd:function(e){ this.setData({ inputValue: e.detail.value, searching: true }) this.setSearchStorage() }, // 清除所有历史 clearAll: function () { wx.setStorageSync('searchData', []) this.setData({ getSearch: [], }) }, // 选择该项历史 selectThis: function (e) { }, // 删除该项历史 deletThis: function (e) { console.log(e) var data = this.data.getSearch data.splice(e.currentTarget.dataset.index,1) this.setData({ getSearch: data }) }, bindInput: function (e) { this.setData({ inputValue: e.detail.value }) console.log('bindInput' + this.data.inputValue) } })