From 44554dfcebb14d182f764661f173f9f090b0f5e2 Mon Sep 17 00:00:00 2001 From: XiaoMo Date: Thu, 6 Apr 2023 16:00:10 +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-16:00:01?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/SearchBox.vue | 5 ++--- src/store/index.js | 4 +--- src/views/search/searchResult/SearchResult.vue | 17 ++++++++++++----- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/components/SearchBox.vue b/src/components/SearchBox.vue index a349247..b56dc78 100755 --- a/src/components/SearchBox.vue +++ b/src/components/SearchBox.vue @@ -53,9 +53,8 @@ export default { watch: { historicalSearch(val, oldval) { - console.log("val", val); if (val.length > 10) this.historicalSearch.slice(0, 10) - this.$store.commit('setHistoricalSearch', val) + else this.$store.commit('setHistoricalSearch', val) } }, @@ -88,8 +87,8 @@ export default { toSearchResult(kw) { if (!kw) return - this.historicalSearch.push(kw) + console.log(this.historicalSearch); if (!this.historicalSearch.includes(kw)) this.historicalSearch.unshift(kw) this.$router.push(`/searchResult?kw=${kw}`) diff --git a/src/store/index.js b/src/store/index.js index 2273ed8..b1c4628 100755 --- a/src/store/index.js +++ b/src/store/index.js @@ -11,12 +11,10 @@ export default new Vuex.Store({ }, mutations: { setHistoricalSearch(state, payload) { + console.log(payload, "payload"); payload = [...new Set(payload)] state.historicalSearch = payload - localStorage.setItem('historicalSearch', JSON.stringify(payload)); - - } }, actions: { diff --git a/src/views/search/searchResult/SearchResult.vue b/src/views/search/searchResult/SearchResult.vue index 47448e2..9cb0f70 100755 --- a/src/views/search/searchResult/SearchResult.vue +++ b/src/views/search/searchResult/SearchResult.vue @@ -15,7 +15,7 @@
大约找到
{{ count }}
条结果
-
+
{{ item.forum }}
@@ -95,8 +95,11 @@ export default { }, historicalSearch(val, oldval) { - if (val.length > 10) this.historicalSearch.slice(0, 10) - this.$store.commit('setHistoricalSearch', val) + console.log("val", val); + if (val.length > 10) this.historicalSearch = val.slice(0, 10) + else this.$store.commit('setHistoricalSearch', val) + + return val }, }, @@ -111,7 +114,8 @@ export default { handleSearchResult() { let kw = this.kw // this.historicalSearch.push(kw) - if (!this.historicalSearch.includes(kw)) this.historicalSearch.unshift(kw) + console.log("this.historicalSearch", this.historicalSearch); + if (!this.historicalSearch.includes(kw)) this.historicalSearch = this.historicalSearch.unshift(kw) this.getSearchResult() }, @@ -147,7 +151,10 @@ export default { this.getSearchResult() }, - + // 跳转详情 + toDetail(tid) { + this.$router.push(`/detailIndex?tid=${tid}`) + }, // 点击清空 input 的值 emptyKw() {