SelectBar.vue
1.38 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
<template>
<div class="select-tab flex" v-if="data.length > 0">
<template v-for="(i) in data">
<div @click="click(i)" :class="['item', tabIndex == i.value ? 'active' : '']" :key="i.value">{{ i.text }}</div>
</template>
</div>
</template>
<script type="text/ecmascript-6">
export default {
name: 'SelectBar',
props: {
list: {
type: Array,
default: () => {
return []
}
},
index: {
type: Number,
default: 0
},
updata: null
},
data () {
return {
tabIndex: this.index,
data: this.list
}
},
watch: {
'index' (n) {
this.tabIndex = n
},
'updata' (n) {
this.data = this.list
this.tabIndex = this.index
}
},
mounted () {
},
methods: {
click (data) {
this.tabIndex = data.value
this.$emit('change', this.tabIndex)
}
}
}
</script>
<style lang="scss" scoped>
.select-tab {
margin: 10px 16px;
height: 28px;
background: #ebeff5;
border-radius: 6px;
box-sizing: border-box;
.item {
font-size: 14px;
font-weight: 400;
color: #666666;
line-height: 28px;
flex: 1;
text-align: center;
}
.active {
height: 24px;
background: #ffffff;
box-shadow: 0px 1px 2px 0px rgba(94, 97, 102, 0.2);
border-radius: 4px;
border: 1px solid rgba(0, 0, 0, 0.04);
color: #3975c6;
line-height: 24px;
}
}
</style>