很多搜索场景内都能用到这个功能
大概就是用户搜索了某个关键字 然后搜索的关键字可以持久的保存下来
下次打开搜索的时候可以达到快速点击搜索的效果
"keyWord">
- methods: {
- search(){
- // historyList 为历史搜索的列表
- // 先做逻辑判断 keyWord 在history内是否存在 如果存在 就把原来的删除 把最新的添加到最前面
- // 如果不存在 就直接加到最前面
- this.historyList.unshift(this.keyWord)
- this.keyWord = ''
- // 把列表储存到本地
- uni.setStorageSync('historyList', this.historyList)
- }
- }
- onLoad(){
- this.historyList = uni.getStorageSync('historyList')
- }