输入框防抖
input(e){
clearTimeout(this.timer)
this.timer=setTimeout(()=>{
this.kw=e
this.getSearchList()
},500)
搜索列表和搜索关键词互斥
v-if="searchResults.length!==0"
搜索关键词重复问题
// 把数组转换为set对象
const set = new Set(this.historyList)
// 移除对应的元素
set.delete(this.kw)
//添加对应的元素
set.add(this.kw)
// 把set对象转换为数组
this.historyList=Array.from(set)
把搜索历史记录持久化存储到本地
//调用uni.setStorageSync(key,value)
uni.setStorageSync('kw',JSON.stringify(this.historyList))
//与data平级
onLoad(){
this.historyList=JSON.parse(uni.getStorageSync('kw')||'[]')
}