a1300399510@qq.com 提交于 2023/04/06 -14:20:02

This commit is contained in:
2023-04-06 14:20:11 +08:00
parent e65241785b
commit 482193fbee
4 changed files with 22 additions and 5 deletions

View File

@@ -11,7 +11,8 @@
<div class="search-input flexacenter">
<div class="form flexacenter">
<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">
</div>
@@ -45,13 +46,14 @@ export default {
searchWinShow: false,//显示搜索弹窗
searchText: '',
showClear: false, //显示清除按钮
historicalSearch: [], // 历史搜索
historicalSearch: this.$store.state.historicalSearch, // 历史搜索
}
},
props: ["issearch", "hotSearchkeywords"],
watch: {
historicalSearch(val, oldval) {
if (val.length > 10) this.historicalSearch.slice(0, 10)
localStorage.setItem('historicalSearch', JSON.stringify(val));
}
},
@@ -83,7 +85,12 @@ export default {
// 跳转搜索结果
toSearchResult(kw) {
if (!kw) return
this.historicalSearch.push(kw)
if (!this.historicalSearch.includes(kw)) this.historicalSearch.unshift(kw)
this.$router.push(`/searchResult?kw=${kw}`)
},
},