fav-tab-block.vue
2.11 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<template>
<div class="tabs-wrap">
<ul class="tabs-list">
<li v-for="(item, index) in tabList" :key="index" :class="{'active': active === index}" @click="changeType(index, true)">
{{item.name}}
<span v-if="item.num" class="t-num">({{item.num}})</span>
</li>
</ul>
</div>
</template>
<script>
import {find} from 'lodash';
export default {
props: {
tabsNum: Array,
activeIndex: Number
},
data() {
return {
tabList: [
{name: '内容', type: 1},
{name: '收藏', type: 2},
],
active: ''
};
},
created() {
this.changeType(this.activeIndex);
this.computetabsNum();
},
methods: {
changeType(index, isClick) {
if (!this.tabList[index]) {
index = 0;
}
this.active = index;
this.$emit('change', index);
},
computetabsNum(a) {
let tabList = this.tabList;
for (let i = this.tabList.length - 1; i >= 0; i--) {
let num = '';
if (this.tabsNum[i] > 0) {
num = this.tabsNum[i];
}
tabList[i].num = num;
}
this.tabList = [...tabList];
},
computeCurrentTab() {
this.changeType(this.activeIndex || 0);
}
},
watch: {
tabsNum: 'computetabsNum',
activeIndex: 'computeCurrentTab'
}
};
</script>
<style>
.tabs-wrap {
padding: 20px 30px 30px;
background-color: #fff;
display: flex;
justify-content: space-between;
align-items: center;
.tabs-list {
display: flex;
li {
font-size: 32px;
color: #b0b0b0;
font-weight: 300;
margin-right: 40px;
}
.active {
color: #222;
font-weight: 500;
position: relative;
&:after {
content: '';
position: absolute;
left: 0;
bottom: -10px;
width: 100%;
height: 8px;
background-color: #d90025;
box-shadow: 0 2px 4px 0 rgba(210, 0, 13, 0.34);
}
}
.t-num {
color: #b0b0b0;
font-size: 24px;
zoom: 0.9;
margin-left: -8px;
}
}
}
</style>