diff --git a/src/components/SearchBox.vue b/src/components/SearchBox.vue index ea4ca39..57baea1 100755 --- a/src/components/SearchBox.vue +++ b/src/components/SearchBox.vue @@ -54,7 +54,7 @@ export default { watch: { historicalSearch(val, oldval) { if (val.length > 10) this.historicalSearch.slice(0, 10) - localStorage.setItem('historicalSearch', JSON.stringify(val)); + this.$store.commit('setHistoricalSearch', val) } }, @@ -98,13 +98,6 @@ 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); - } } diff --git a/src/store/index.js b/src/store/index.js index 287630c..fdb3f59 100755 --- a/src/store/index.js +++ b/src/store/index.js @@ -12,13 +12,19 @@ export default new Vuex.Store({ mutations: { setHistoricalSearch(state, payload) { state.historicalSearch = payload + + localStorage.setItem('historicalSearch', JSON.stringify(payload)); + + } }, actions: { + // 获取历史搜索的数据 fetchHistoricalSearch({ commit }) { let historicalSearch = JSON.parse(localStorage.getItem('historicalSearch')) || [] commit('setHistoricalSearch', historicalSearch) - } + }, + }, modules: { } diff --git a/src/views/search/searchResult/SearchResult.vue b/src/views/search/searchResult/SearchResult.vue index 4a0101a..0b2bb03 100755 --- a/src/views/search/searchResult/SearchResult.vue +++ b/src/views/search/searchResult/SearchResult.vue @@ -19,7 +19,6 @@