From e65241785bc181f73b937ded65af30e1d70b37e2 Mon Sep 17 00:00:00 2001 From: XiaoMo Date: Thu, 6 Apr 2023 12:40:11 +0800 Subject: [PATCH] =?UTF-8?q?a1300399510@qq.com=20=E6=8F=90=E4=BA=A4?= =?UTF-8?q?=E4=BA=8E=202023/04/06=20-12:40:02?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/SearchBox.vue | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/components/SearchBox.vue b/src/components/SearchBox.vue index 5599c8b..22646ba 100755 --- a/src/components/SearchBox.vue +++ b/src/components/SearchBox.vue @@ -21,7 +21,8 @@
历史搜索
- 香港大学 + {{ item + }}
@@ -49,11 +50,10 @@ export default { }, props: ["issearch", "hotSearchkeywords"], - mounted() { - let hotSearchkeywords = ["香港大学","香港大学"] - var cachedData = localStorage.setItem('hotSearchkeywords',[]) || []; - - // var cachedData = localStorage.getItem('hotSearchkeywords') || []; + watch: { + historicalSearch(val, oldval) { + localStorage.setItem('historicalSearch', JSON.stringify(val)); + } }, methods: { @@ -83,6 +83,7 @@ export default { // 跳转搜索结果 toSearchResult(kw) { + this.historicalSearch.push(kw) this.$router.push(`/searchResult?kw=${kw}`) }, }, @@ -90,6 +91,13 @@ export default { if (this.searchText.length > 0) this.showClear = true else this.showClear = false + + // let hotSearchkeywords = ["香港大学", "香港大学"] + // console.log(JSON.stringify(hotSearchkeywords)); + + this.historicalSearch = JSON.parse(localStorage.getItem('historicalSearch')) || [] + console.log(this.historicalSearch); + } }