uni-app浏览历史记录功能实现
searchStart: function () {
let _this = this;
if (_this.searchText == '') {//搜索关键词为空
uni.showToast({//提示信息
title: '请输入关键字',
icon: 'none',
duration: 1000
});
} else {
uni.getStorage({//从缓存中取搜索历史记录的数组
key: 'search_cache',
success(res) {//获取成功
let list = res.data;
for (let i in list) {//循环遍历
if (list[i] == _this.searchText) {//如果缓存数组中有搜索关键词
list.splice(i, 1)//删除数组中的该关键词
}
}
list.unshift(_this.searchText);//将搜索关键词添加到数组开头
list.splice(6)//只保留6个
_this.hList = list;
uni.setStorage({//将新的数组存入缓存
key: 'search_cache',
data: _this.hList,
});
_this.search(_this.searchText);//搜索
},
fail() {//没有获取到缓存
_this.hList = [];
_this.hList.push(_this.searchText);
uni.setStorage({
key: 'search_cache',
data: _this.hList,
});
_this.search(_this.searchText);//搜索
}
})
}
}
- 相关阅读
- 过滤输入字符串中的危险符号
- html表单里面的label详细
- 万家乐橱柜网站
- 纯asp根据当前日期计算出当前年份的属相
- 网站终于在计划时间内完成了
- 超过服务期限如何办?
- ASP.NET常用的三十三种实用代码(上)
- uni-app设置像页面html或者body的全局背景色
- 共有0条关于《uni-app浏览历史记录功能实现》的评论
- 发表评论
您发布的评论即表示同意遵守以下条款:
一、不得利用本站危害国家安全、泄露国家秘密,不得侵犯国家、社会、集体和公民的合法权益;
二、不得发布国家法律、法规明令禁止的内容;互相尊重,对自己在本站的言论和行为负责;
三、本站对您所发布内容拥有处置权。
- 更多>>同类信息
- uni-app开发表单input组件的一些规则说明自己预留使用
- uni-app:使用uni.downloadFile下载word或pdf文件并保存到手机
- 小程序中利用addPhoneContact将联系人的信息添加到手机通讯录支持保存联系人头像
- 微信小程序打开客服提示:该小程序提供的服务出现故障,请稍后重试
- 微信小程序客服会话只能过button让用户主动触发
- uni-app开发微信小程序使用button的open-type为contact调用微信客服不能用view或者js调用