forked from N3-components/N3-components
-
Notifications
You must be signed in to change notification settings - Fork 0
/
n3CheckboxBtn.vue
executable file
·64 lines (61 loc) · 1.11 KB
/
n3CheckboxBtn.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
<template>
<n3-button
@click.prevent="handleClick"
:class="classObj"
:disabled="disabled"
:type="checked ? 'primary' : 'default'">
<slot></slot>
</n3-button>
</template>
<script>
import n3Button from './n3Button'
import type from './utils/type'
export default {
props: {
value: {
type: String
},
checked: {
type: Boolean,
default: false,
twoway: true
},
disabled: {
type: Boolean,
default: false
},
onChange: {
type: Function
},
prefixCls: {
type: String,
default: 'n3'
}
},
events: {
'n3@checkboxgroupChange' (val) {
this.checked = val.indexOf(this.value) > -1
}
},
computed: {
classObj () {
let {prefixCls} = this
let klass = {}
klass[prefixCls + '-checked-btn'] = true
return klass
}
},
methods: {
handleClick () {
this.checked = !this.checked
this.$dispatch('n3@checkboxChange', this)
if (type.isFunction(this.onChange)) {
this.onChange(this.checked)
}
}
},
components: {
n3Button
}
}
</script>