saveKeyword(keyword) {
console.log(uni.getStorageSync('historyList'),'先获取缓存historyList');
uni.getStorage({
key: 'historyList',
success: (res) => {
console.log('获取缓存成功',res);
let OldKeys = res.data || [];
let findIndex = OldKeys.indexOf(keyword);
if (findIndex == -1) {
OldKeys.unshift(keyword);
} else {
OldKeys.splice(findIndex, 1);
OldKeys.unshift(keyword);
}
OldKeys.length > 10 && OldKeys.pop();
uni.setStorage({
key: 'historyList',
data: OldKeys
});
this.historyList = OldKeys;
},
fail: (e) => {
let OldKeys = [keyword];
uni.setStorage({
key: 'historyList',
data: OldKeys
});
this.oldKeywordList = OldKeys;
console.log('获取缓存失败');
}
});
},