[新增] 让 checkbox 具有响应式的能力

This commit is contained in:
就眠仪式 2021-09-30 02:18:34 +08:00
parent e65a4e7588
commit d3fd62254b

View File

@ -20,7 +20,7 @@
</template>
<script setup name="LayCheckbox" lang="ts">
import { defineProps, ref } from 'vue'
import { defineProps, ref, watch } from 'vue'
const props =
defineProps<{
@ -33,11 +33,13 @@ const props =
const hasValue = ref(false)
if (props.modelValue.includes(props.label)) {
hasValue.value = true
} else {
hasValue.value = 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'])