MyTabBar.vue
2.0 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
<template>
<div class="tab-bar-view">
<div class="tab-bar-item" v-for="(item, index) in tabBarList" :key="index" :class="{ activity: activityTabBarIndex === index }" @click="itemClick(item, index)">
<div v-if="item.icon" class="tab-bar-icon van-icon" :class="`van-icon-${item.icon}`" @click.stop="itemClick(item, index)"></div>
<div class="tab-bar-name">{{ item.label }}</div>
</div>
</div>
</template>
<script>
export default {
name: 'MyTabBar',
props: {
value: {
type: [String, Number],
required: true
},
tabBarList: {
type: Array,
default: () => {
return []
}
}
},
computed: {
activityTabBarIndex: {
get() {
let currentIndex = 0
if (typeof this.value === 'string') {
this.tabBarList.forEach((item, index) => {
if (item.name === this.value) {
currentIndex = index
}
})
} else if (typeof this.value === 'number') {
currentIndex = this.value
}
return currentIndex
},
set(index) {
this.$emit('input', index)
}
}
},
data() {
return {}
},
methods: {
itemClick(item, index) {
console.log('tabbar-itemClick-index', index)
this.activityTabBarIndex = index
this.$emit('change', item)
}
}
}
</script>
<style lang="scss" scoped>
.tab-bar-view {
position: fixed;
left: 0;
bottom: 0;
width: 100%;
height: 51px;
display: flex;
align-items: center;
padding-bottom: constant(safe-area-inset-bottom);
padding-bottom: env(safe-area-inset-bottom);
background-color: #fff;
box-shadow: 0 0 10px #d9d9d9;
border-top: 1px solid #e3e3e3;
.tab-bar-item {
height: 100%;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
flex: 1;
font-size: 12px;
line-height: 1;
color: #7d7e80;
cursor: pointer;
.tab-bar-icon {
margin-bottom: 4px;
font-size: 22px;
}
&.activity {
color: #1989fa;
}
}
}
</style>