AdaKing88
2023-08-23 9cad48db6c56c3e2796a9d6da881817ef13b6eca
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
<template>
    <el-checkbox-group v-model="value" :disabled="form_disabled[data.prop]" @change="handlerChange">
        <el-checkbox v-for="checkbox in data.options" :label="checkbox.value" :key="checkbox.value">{{ checkbox.label }}</el-checkbox>
    </el-checkbox-group>
 
</template>
 
<script>
import { reactive, toRefs } from 'vue';
export default {
    name: "CheckboxComponent",
    props: {
        data: {
            type: Object,
            default: () => ({})
        },
        value: {
            type: Array,
            default: () => ([])
        }
    },
    emits: ['update:value', 'callback'],
    setup(props, { emit }){
        const data = reactive({
            value: '',
            data: props.data
        })
        
        const handlerChange = (val) => {
            emit("update:value", val)
            emit("callback", {
                type: 'checkbox',
                value: val,
                data: props.data
            })
        }
        return {
            ...toRefs(data),
            handlerChange
        }
    }
}
</script>