forked from N3-components/N3-components
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathn3Radio.vue
83 lines (79 loc) · 1.63 KB
/
n3Radio.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
<template>
<label class="{{prefixCls}}-radio-con">
<span :class="wrapClasses">
<span class="{{prefixCls}}-radio-inner"></span>
<input
type="radio"
:disabled="disabled"
:checked="checked"
class="{{prefixCls}}-radio-input"
@click.prevent="handleClick" >
</span>
<span><slot></slot></span>
<validate
:name="name"
:rules="rules"
:valid-status.sync="validStatus"
:custom-validate="customValidate"
:value="checked"
:results.sync="validateResults">
</validate>
</label>
</template>
<script>
import type from './utils/type'
import valMixin from './valMixin'
import validate from './validate'
export default {
mixins: [valMixin],
props: {
value: {
type: String
},
checked: {
type: Boolean,
default: false,
twoway: true
},
disabled: {
type: Boolean,
default: false
},
onChange: {
type: Function
},
prefixCls: {
type: String,
default: 'n3'
}
},
components: {
validate
},
events: {
'n3@radiogroupChange' (val) {
this.checked = val === this.value
}
},
computed: {
wrapClasses () {
let klass = {}
let {prefixCls, checked, disabled} = this
klass[prefixCls + '-radio-span'] = true
klass[prefixCls + '-radio-checked'] = checked
klass[prefixCls + '-radio-disabled'] = disabled
return klass
}
},
methods: {
handleClick () {
if (this.checked) return
this.checked = true
this.$dispatch('n3@radioChange', this.value)
if (type.isFunction(this.onChange)) {
this.onChange(this.checked)
}
}
}
}
</script>