forked from N3-components/N3-components
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathn3RadioGroup.vue
executable file
·110 lines (101 loc) · 2.05 KB
/
n3RadioGroup.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<template>
<div class="{{prefixCls}}-btn-group {{prefixCls}}-radio-group">
<template v-if="options">
<n3-radio
v-if="type==='checkbox'"
v-for="item in options"
:value="item.value"
:checked="item.checked"
:disabled="item.disabled">
{{item.label}}
</n3-radio>
<n3-radio-btn
v-if="type==='button'"
v-for="item in options"
:value="item.value"
:checked="item.checked"
:disabled="item.disabled">
{{item.label}}
</n3-radio-btn>
</template>
<template v-else>
<slot></slot>
</template>
<validate
:name="name"
:rules="rules"
:valid-status.sync="validStatus"
:custom-validate="customValidate"
:value="value"
:results.sync="validateResults">
</validate>
</div>
</template>
<script>
import n3Radio from './n3Radio'
import n3RadioBtn from './n3RadioBtn'
import valMixin from './valMixin'
import validate from './validate'
import type from './utils/type'
export default {
mixins: [valMixin],
props: {
value: {
type: String,
twoWay: true
},
type: {
type: String,
default: 'checkbox'
},
options: {
type: Array
},
onChange: {
type: Function
},
prefixCls: {
type: String,
default: 'n3'
}
},
methods: {
init (val) {
if (!type.isUndefined(val)) {
this.value = val
} else {
let children = this.$children
let ret
children.forEach((item) => {
item.checked ? ret = item.value : ''
})
this.value = ret
}
}
},
events: {
'n3@radioChange' (val) {
this.init(val)
}
},
watch: {
value () {
this.$broadcast('n3@radiogroupChange', this.value)
if (type.isFunction(this.onChange)) {
this.onChange(this.value)
}
},
options () {
this.init()
}
},
ready () {
this.init()
},
components: {
n3Radio,
n3RadioBtn,
validate
}
}
</script>