forked from ElemeFE/vue-desktop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
radio-group.vue
58 lines (48 loc) · 1.04 KB
/
radio-group.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
<style>
.d-radio-group input[type="radio"] {
display: inline-block;
}
.d-radio-group label {
font-size: 14px;
vertical-align: text-bottom;
}
</style>
<template>
<div class="d-radio-group"><slot></slot></div>
</template>
<script type="text/ecmascript-6">
var idSeed = 1;
const prefix = 'radio-group-';
var syncValue = (group, value) => {
var children = group.$children;
children.forEach(function(child) {
if (child.value !== undefined && child.value == value) { // eslint-disable-line eqeqeq
if (child.$els.editor) {
child.$els.editor.checked = true;
}
}
});
};
export default {
props: ['value'],
watch: {
value(val) {
syncValue(this, val);
}
},
methods: {
$setValue(value) {
this.value = value;
}
},
created() {
this.$radioName = prefix + idSeed++;
},
ready() {
var value = this.value;
if (typeof value !== 'undefined') {
syncValue(this, value);
}
}
};
</script>