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() {