updown.vue
1.21 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
<template>
<li class="order-item" :class="active" @click="clickHandler">
<span class="order-name">{{txt}}</span>
<span class="order-icon">
<i class="icon icon-sort-asc" :class="{active: $parent.val === vals[0]}"></i>
<i class="icon icon-sort-desc" :class="{active: $parent.val === vals[1]}"></i>
</span>
</li>
</template>
<style>
.order-item .icon {
color: #b0b0b0;
&.active {
color: #000;
}
}
</style>
<script>
module.exports = {
props: {
txt: String,
vals: Array // [asc, desc]
},
data: function() {
return {};
},
computed: {
active: function() {
const index = this.vals.indexOf(this.$parent.val);
if (index >= 0) {
return {
active: true,
};
}
}
},
methods: {
clickHandler: function() {
let index = this.vals.indexOf(this.$parent.val);
if (index === -1) {
this.$parent.val = this.vals[0];
} else {
index = index === 0 ? 1 : 0;
this.$parent.val = this.vals[index];
}
}
}
};
</script>