checkbox.vue
1.41 KB
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
<template>
<div class="checkbox-control" :class="layoutClass">
<!-- <template v-for="item in list"> -->
<input type="checkbox" :value="item.value || item" v-model="selected" :id="uuid + $index">
<label @click="manualSelect" class="checkbox" :for="uuid+ $index">{{isAlone ? '' : (item.label || item)}}</label>
<!-- </template> -->
</div>
</template>
<script>
module.exports = {
props: {
list: {
type: Array,
required: true
},
layout: {
type: Array,
default: ''
},
selected: {
type: Array,
twoWay: true
}
},
data: function () {
return {
isAlone: false
};
},
computed: {
layoutClass: function () {
var clazz = [];
for (var i = 0, len = this.layout.length; i < len; i++) {
if (this.layout[i] === 'control') {
continue;
}
if (this.layout[i] === 'alone') {
this.isAlone = true;
}
clazz.push('checkbox-' + this.layout[i]);
}
return clazz;
}
},
methods: {
manualSelect: function () {
var self = this;
window.setTimeout(function () {
self.$dispatch('manual-change');
}, 50);
}
},
data: function () {
return {
uuid: 'checkbox_' + Math.random().toString().substr(2).toString(32)
};
}
};
</script>