wx.setStorage({
key:"key",
data:"value"
})
wx.getStorage({
key: 'key',
success: function(res) {
console.log(res.data)
}
})
wx.getStorageInfo({
success: function(res) {
console.log(res.keys)
console.log(res.currentSize)
console.log(res.limitSize)
}
})
wx.removeStorage({
key: 'key',
success: function(res) {
console.log(res.data)
}
})
<input type="text" class="search-icon" placeholder="请输入要搜索的内容" bindinput="searchNameInput"/>
<text bindtap="setSearchStorage">搜索</text>
<view>
<view>
<text style="float:left;" bindtap="deleteHistory">历史搜索</text>
<text style="float:right;" bindtap="deleteHistory">删除搜索历史</text>
</view>
<view>
<view class="search-list" wx:for="{{searchData}}" wx:key="item">
<view>{{item == null?'暂无数据':item}}</view>
</view>
</view>
</view>
//获取用户输入框的值
searchNameInput:function(e){
var that = this;
that.setData({
inputValue:e.detail.value
})
}
e.detail.value就代表了当前输入值
//将用户输入的内容存入本地缓存,并且将搜索数据放到首页
setSearchStorage:function(){
var that = this
if(this.data.inputValue != ''){
//调用API向本地缓存存入数据
var searchData = wx.getStorageSync('searchData') || []
searchData.push(this.data.inputValue)
wx.setStorageSync('searchData', searchData)
//读取用户搜索商品
var name = this.data.inputValue
wx.request({
url: 'www.shop.com/home/product/search',
data: {name:name},
method: 'GET',
success: function(res){
that.setData({
goodsList: res.data.info,
})
},
})
}
}
//从本地获取历史搜索数据
var searchData = wx.getStorageSync('searchData')||[]
this.setData({
searchData:searchData
})
deleteHistory
//删除历史搜索数据
deleteHistory:function(){
var that = this
wx.showModal({
title: '提示',
content: '是否删除历史搜索',
success: function(res) {
if (res.confirm) {
wx.setStorageSync('searchData', []);
wx.switchTab({
url: '/pages/index/index',
})
}
}
})
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有