-
Notifications
You must be signed in to change notification settings - Fork 13
/
switch.vue
87 lines (82 loc) · 1.24 KB
/
switch.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
81
82
83
84
85
86
87
<template>
<div :class="className" @click="onClick">
<span class="open">{{ openName }}</span>
<span class="close">{{ closeName }}</span>
</div>
</template>
<script>
'use strict';
export default {
props: {
value: {
default: true,
twoWay: true
},
// sm小 md中 lg大
size: {
type: String,
default: 'md中'
},
// blue red green orange
color: {
type: String,
default: 'red'
},
openValue: {
default: true
},
closeValue: {
default: false
},
openName: {
type: String,
default: '是'
},
closeName: {
type: String,
default: '否'
},
disabled: {
type: Boolean,
default: false
}
},
computed: {
className() {
let {
value,
openValue,
closeValue,
size,
color,
disabled
} = this;
return {
'vue-switch': true,
'z-on': value === openValue,
'z-disabled': disabled,
['s-' + size]: true,
['c-' + color]: true
};
}
},
methods: {
onClick() {
let {
disabled,
value,
openValue,
closeValue
} = this;
if (!disabled) {
if (openValue === value) {
this.value = closeValue;
} else {
this.value = openValue;
}
}
}
}
}
</script>
<style lang="sass" scoped>@import "./scss/switch.scss"</style>