rest(checkbox): 重构 checkbox 逻辑
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user