a1300399510@qq.com 提交于 2023/04/06 -12:40:02

This commit is contained in:
XiaoMo 2023-04-06 12:40:11 +08:00
parent d7807870c5
commit e65241785b

View File

@ -21,7 +21,8 @@
<div class="search-content flexcolumn" v-if="historicalSearch.length != 0"> <div class="search-content flexcolumn" v-if="historicalSearch.length != 0">
<div class="search-text">历史搜索</div> <div class="search-text">历史搜索</div>
<div class="search-label"> <div class="search-label">
<span v-for="(item, index) in historicalSearch" :key="index">香港大学</span> <span v-for="(item, index) in historicalSearch" :key="index" @click.stop="toSearchResult(item)">{{ item
}}</span>
</div> </div>
</div> </div>
<!-- 热门搜索 --> <!-- 热门搜索 -->
@ -49,11 +50,10 @@ export default {
}, },
props: ["issearch", "hotSearchkeywords"], props: ["issearch", "hotSearchkeywords"],
mounted() { watch: {
let hotSearchkeywords = ["香港大学","香港大学"] historicalSearch(val, oldval) {
var cachedData = localStorage.setItem('hotSearchkeywords',[]) || []; localStorage.setItem('historicalSearch', JSON.stringify(val));
}
// var cachedData = localStorage.getItem('hotSearchkeywords') || [];
}, },
methods: { methods: {
@ -83,6 +83,7 @@ export default {
// //
toSearchResult(kw) { toSearchResult(kw) {
this.historicalSearch.push(kw)
this.$router.push(`/searchResult?kw=${kw}`) this.$router.push(`/searchResult?kw=${kw}`)
}, },
}, },
@ -90,6 +91,13 @@ export default {
if (this.searchText.length > 0) this.showClear = true if (this.searchText.length > 0) this.showClear = true
else this.showClear = false else this.showClear = false
// let hotSearchkeywords = ["", ""]
// console.log(JSON.stringify(hotSearchkeywords));
this.historicalSearch = JSON.parse(localStorage.getItem('historicalSearch')) || []
console.log(this.historicalSearch);
} }
} }
</script> </script>