
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);//搜索
}
})
}
}
您發布的評論即表示同意遵守以下條款:
一、不得利用本站危害國家安全、泄露國家秘密,不得侵犯國家、社會、集體和公民的合法權益;
二、不得發布國家法律、法規明令禁止的內容;互相尊重,對自己在本站的言論和行為負責;
三、本站對您所發布內容擁有處置權。