SearchHistory.vue
1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<template>
<div class="history">
<div class="history_title" v-if="historys.length">
<span>搜索历史</span>
<img :src="require('@/assets/icon/trash.png')" @click="handleClear">
</div>
<div class="historyList" v-if="historys.length">
<ul>
<li v-for="(item,index) in historys" :key="index" @jump="jumItem(item)">{{item}}</li>
</ul>
</div>
<div class="noData" v-else>
暂无历史记录
</div>
</div>
</template>
<script>
import { mapState } from 'vuex'
export default {
name: 'SearchHistory',
props: {
stateKey: String,
},
computed: {
...mapState('search', {
historys (state) {
return state[this.stateKey] || []
}
}),
},
methods: {
jumItem (val) {
this.$emit('jumpPage', val)
},
handleClear () {
this.$store.dispatch('search/ACleanHistory', this.stateKey)
this.$emit('clear')
}
}
}
</script>
<style lang="less" scoped>
.history {
display: flex;
flex-direction: column;
padding: 20px 15px;
background-color: #fafafa;
height: 100%;
.history_title {
display: flex;
justify-content: space-between;
span {
color: #666;
font-size: 11px;
}
img {
width: 25px;
height: 25px;
}
}
}
.historyList {
ul {
display: flex;
flex-wrap: wrap;
li {
display: flex;
justify-content: center;
padding: 7px 15px;
background-color: #fff;
border-radius: 15px;
margin-right: 10px;
margin-top: 10px;
min-width: 80px;
font-size: 12px;
color: #161818;
word-break: break-all;
}
}
}
.noData {
text-align: center;
color: #666;
}
</style>