SearchHistory.vue 1.66 KB
<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', [this.stateKey]),

    historys () {
      return this[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: 100vh;
  .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>