-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathradio-group.js
45 lines (45 loc) · 1.21 KB
/
radio-group.js
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
// Define a new component called yes-no-radio
Vue.component('yes-no-radio', {
data: function () {
return {
newValue: this.value
};
},
props: ['value', 'name'],
computed: {
computedValue: {
get() {
return this.newValue;
},
set(value) {
this.newValue = value;
this.$emit('input', value);
}
}
},
watch: {
/**
* When v-model change, set internal value.
*/
value(value) {
this.newValue = value;
}
},
template: `<div>
<label class="btn btn-default">
<input
type="radio"
v-model.number="computedValue"
:name="name"
:checked="value === 1" value="1"> Yes
</label>
<label class="btn btn-default">
<input
type="radio"
v-model.number="computedValue"
:name="name"
:checked="value === 0"
value="0"> No
</label>
</div>`,
});