clll
2023-09-08 0b83163518f23e4571f3f510c38e9a25f46b6d07
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
<template>
  <keep-alive>
    <div 
      class="tag" 
      :class="{ active: isActive }" 
      @click="switchTag(tag)">
      <span>{{ tag }}</span>
      <i class="el-icon-close" @click.stop="removeTag(tag)"></i>
    </div>
  </keep-alive>
</template>
 
<script>
export default {
  props: {
    tag: {
      type: String,
      required: true
    },
    activeTag: {
      type: String,
      required: true
    }
  },
  computed: {
    isActive() {
      return this.tag === this.activeTag;
    },
    tagData() {
      return this.$store.getters.getTagData(this.tag);
    }
  },
  methods: {
    removeTag(tag) {
      this.$emit('removeTag', tag);
    },
    switchTag(tag) {
  this.$emit('switchTag', tag);
  this.$router.push('/' + tag); // 切换到指定路由
}
    
  }
}
</script>
 
<style scoped>
.tag {
  display: inline-block;
  margin-right: 10px;
  padding: 4px 10px;
  border-radius: 4px;
  background-color: #f0f0f0;
  cursor: pointer;
}
 
.tag.active {
  background-color: #409eff;
  color: #fff;
}
 
.tag span {
  margin-right: 5px;
}
 
.tag i {
  margin-left: 5px;
  font-size: 5px;
  cursor: pointer;
}
</style>