rest(checkbox): 重构 checkbox 逻辑

This commit is contained in:
就眠仪式
2021-10-11 15:46:44 +08:00
parent e1c8e1f7c6
commit b741da239b
3 changed files with 47 additions and 31 deletions

View File

@@ -8,7 +8,7 @@
'layui-checkbox-disbaled layui-disabled': disabled,
},
'layui-form-checkbox',
hasValue ? 'layui-form-checked' : '',
props.modelValue.includes(props.label) ? 'layui-form-checked' : '',
]"
:lay-skin="skin"
>
@@ -24,7 +24,7 @@ import { defineProps, ref, watch } from 'vue'
const props =
defineProps<{
modelValue: Array<unknown>
modelValue: string[]
label: string
disabled?: boolean
name?: string
@@ -33,14 +33,6 @@ const props =
const hasValue = ref(false)
watch(props.modelValue, (val) => {
if (props.modelValue.includes(props.label)) {
hasValue.value = true
} else {
hasValue.value = false
}
},{immediate: true})
const emit = defineEmits(['update:modelValue'])
const handleClick = function () {
@@ -51,14 +43,6 @@ const handleClick = function () {
let index = props.modelValue.indexOf(props.label)
props.modelValue.splice(index, 1)
}
props.modelValue.includes(props.label)
? (hasValue.value = true)
: (hasValue.value = false)
if (props.modelValue.includes(props.label)) {
hasValue.value = true
} else {
hasValue.value = false
}
emit('update:modelValue', props.modelValue)
}
}