
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);//搜索
}
})
}
}
您发布的评论即表示同意遵守以下条款:
一、不得利用本站危害国家安全、泄露国家秘密,不得侵犯国家、社会、集体和公民的合法权益;
二、不得发布国家法律、法规明令禁止的内容;互相尊重,对自己在本站的言论和行为负责;
三、本站对您所发布内容拥有处置权。