a1300399510@qq.com 提交于 2023/04/06 -14:20:02
This commit is contained in:
parent
e65241785b
commit
482193fbee
@ -11,7 +11,10 @@ export default {
|
|||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
mounted() {
|
||||||
|
this.$store.dispatch('fetchHistoricalSearch')
|
||||||
|
},
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
@ -11,7 +11,8 @@
|
|||||||
<div class="search-input flexacenter">
|
<div class="search-input flexacenter">
|
||||||
<div class="form flexacenter">
|
<div class="form flexacenter">
|
||||||
<img class="search-icon" src="@/assets/img/headerNav/search.png">
|
<img class="search-icon" src="@/assets/img/headerNav/search.png">
|
||||||
<input class="flex1" ref="searchInput" v-model="searchText" type="text" placeholder="请输入搜索关键词" />
|
<input class="flex1" ref="searchInput" v-model="searchText" type="text" placeholder="请输入搜索关键词"
|
||||||
|
@keydown.enter="toSearchResult(searchText)" />
|
||||||
<img v-if="searchText" @click.stop="clearText()" class="clear-text" src="@/assets/img/icon/clear.png">
|
<img v-if="searchText" @click.stop="clearText()" class="clear-text" src="@/assets/img/icon/clear.png">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -45,13 +46,14 @@ export default {
|
|||||||
searchWinShow: false,//显示搜索弹窗
|
searchWinShow: false,//显示搜索弹窗
|
||||||
searchText: '',
|
searchText: '',
|
||||||
showClear: false, //显示清除按钮
|
showClear: false, //显示清除按钮
|
||||||
historicalSearch: [], // 历史搜索
|
historicalSearch: this.$store.state.historicalSearch, // 历史搜索
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
props: ["issearch", "hotSearchkeywords"],
|
props: ["issearch", "hotSearchkeywords"],
|
||||||
|
|
||||||
watch: {
|
watch: {
|
||||||
historicalSearch(val, oldval) {
|
historicalSearch(val, oldval) {
|
||||||
|
if (val.length > 10) this.historicalSearch.slice(0, 10)
|
||||||
localStorage.setItem('historicalSearch', JSON.stringify(val));
|
localStorage.setItem('historicalSearch', JSON.stringify(val));
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -83,7 +85,12 @@ export default {
|
|||||||
|
|
||||||
// 跳转搜索结果
|
// 跳转搜索结果
|
||||||
toSearchResult(kw) {
|
toSearchResult(kw) {
|
||||||
|
|
||||||
|
if (!kw) return
|
||||||
this.historicalSearch.push(kw)
|
this.historicalSearch.push(kw)
|
||||||
|
|
||||||
|
if (!this.historicalSearch.includes(kw)) this.historicalSearch.unshift(kw)
|
||||||
|
|
||||||
this.$router.push(`/searchResult?kw=${kw}`)
|
this.$router.push(`/searchResult?kw=${kw}`)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -5,12 +5,20 @@ Vue.use(Vuex)
|
|||||||
|
|
||||||
export default new Vuex.Store({
|
export default new Vuex.Store({
|
||||||
state: {
|
state: {
|
||||||
|
historicalSearch: []
|
||||||
},
|
},
|
||||||
getters: {
|
getters: {
|
||||||
},
|
},
|
||||||
mutations: {
|
mutations: {
|
||||||
|
setHistoricalSearch(state, payload) {
|
||||||
|
state.historicalSearch = payload
|
||||||
|
}
|
||||||
},
|
},
|
||||||
actions: {
|
actions: {
|
||||||
|
fetchHistoricalSearch({ commit }) {
|
||||||
|
let historicalSearch = JSON.parse(localStorage.getItem('historicalSearch')) || []
|
||||||
|
commit('setHistoricalSearch', historicalSearch)
|
||||||
|
}
|
||||||
},
|
},
|
||||||
modules: {
|
modules: {
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,7 @@
|
|||||||
<div class="result-info flexacenter flex1">
|
<div class="result-info flexacenter flex1">
|
||||||
<div class="user-info flexacenter">
|
<div class="user-info flexacenter">
|
||||||
<img class="icon-head" :src="item.avatar">
|
<img class="icon-head" :src="item.avatar">
|
||||||
<div class="user-name">{{ item.author }}</div>
|
<div class="user-name" v-html="item.author"></div>
|
||||||
</div>
|
</div>
|
||||||
<div class="item-data flexacenter">
|
<div class="item-data flexacenter">
|
||||||
<div class="item-data-item flexacenter">
|
<div class="item-data-item flexacenter">
|
||||||
@ -42,7 +42,6 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
<!-- 精华 -->
|
<!-- 精华 -->
|
||||||
<div class="rightTop" v-if="item.digest > 0">
|
<div class="rightTop" v-if="item.digest > 0">
|
||||||
<img class="rightTop-img" src="@/assets/img/icon/topRight .png">
|
<img class="rightTop-img" src="@/assets/img/icon/topRight .png">
|
||||||
|
Loading…
x
Reference in New Issue
Block a user