Mr.Shi
2023-08-11 6e19ef63c0a87588abd76c04ab228a73e3060ea4
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
<template>
    <div class="tags">
        <div class="tags_item" :class="{ 'active': item.isActive }" v-for="(item, i) in props.dataList" :key="item.id" @click="changeItem(i, item.id)">
            <span>{{item.name}}</span>
            <div class="tags_item_x" v-if="item.isActive"></div>
        </div>
    </div>
</template>
 
<script setup lang="ts">
    import { defineProps, defineEmits } from 'vue'
 
    const props = defineProps({
        dataList: {
            type: Array,
            required: false,
            default: []
        }
    })
 
    const emit = defineEmits(['change'])
 
    // 切换tags
    const changeItem = (i: number, id: string | number) => {
        emit('change', id)
        props.dataList.forEach((item, index) => {
            item.isActive = index === i;
        })
    }
</script>
 
<style lang="scss" scoped>
.tags {
    width: 100%;
    display: flex;
    .active {
        font-size: 32px;
        font-weight: 500;
        color: #222222;
        /*padding-bottom: 18px;*/
    }
    .tags_item {
        margin-right: 48px;
        position: relative;
        span {
            font-size: 28px;
            font-weight: 400;
            color: #555555;
        }
        .tags_item_x {
            position: absolute;
            bottom: -18px;
            left: 50%;
            transform: translate(-50%, 0);
            width: 40px;
            height: 8px;
            background: #4275FC;
            border-radius: 6px;
        }
    }
}
</style>