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