-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTabBarItem.vue
80 lines (75 loc) · 1.43 KB
/
TabBarItem.vue
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
<style lang="stylus">
.TabBarItem {
display: flex;
flex: 1;
height: 48px;
line-height: 1;
align-items: center;
justify-content: center;
color: #757575;
font-size: 13px;
}
.TabBarItem--title {
display: block;
height: 13px;
}
.TabBarItem--icon {
height: 22px;
padding-bottom: 2px;
text-align: center;
img {
height: 100%;
}
}
.TabBarItem.selected {
color: #2b8ff7;
}
</style>
<template>
<div class="TabBarItem" :class="{'selected': selected}" @click="handleClick">
<div class="TabBarItem--bd">
<div class="TabBarItem--icon" v-if="hasSlot">
<slot v-if="selected === false" name="icon"></slot>
<slot v-if="selected === true" name="icon-selected"></slot>
</div>
<span class="TabBarItem--title">{{title}}</span>
</div>
</div>
</template>
<script>
export default {
name: 'TabBarItem',
props: {
// the title
title: {
type: String,
required: true,
default: ''
},
// navigate to another URL by Router
to: String,
selected: {
type: Boolean,
required: true,
default: false
}
},
computed: {
// whether has slot
hasSlot() {
return Object.keys(this.$slots).length > 0
}
},
methods: {
handleClick() {
if (this.to && this.$router) {
// do not produce history, It is not necessary
this.$router.replace(this.to)
}
else {
this.$emit('click')
}
}
}
}
</script>