diff --git a/src/pages/View/checkbox.vue b/src/pages/View/checkbox.vue index bb2f5df..339c39e 100644 --- a/src/pages/View/checkbox.vue +++ b/src/pages/View/checkbox.vue @@ -4,7 +4,11 @@
{{ props.serial_num }} - {{ props.title }} 多选 选答 唯一 + {{ props.title }} + 多选 + 选答 + 唯一 +
{{ props.describe }}
@@ -25,7 +29,7 @@
- +
@@ -57,6 +61,7 @@ const otherAnswer = ref(''); const answerArr = ref([]); const emits = defineEmits(['update:answer']); const otherAnswerChecked = ref(false) +const otherCheckbox = ref(null); const deleteOldAnswer = () => { const otherIndex = answerArr.value.indexOf(otherAnswer.value); @@ -64,8 +69,9 @@ const deleteOldAnswer = () => { answerArr.value.splice(otherIndex, 1); } } + const updateOtherAnswer = (event: Event) => { - if(document.getElementById("other").checked === true) { + if (otherCheckbox.value && otherCheckbox.value.checked) { const value = (event.target as HTMLInputElement).value; deleteOldAnswer(); otherAnswer.value = value; @@ -78,7 +84,7 @@ const filteredAnswerArr = computed(() => { }) watch(filteredAnswerArr, () => { - if(document.getElementById("other").checked === true && !answerArr.value.includes(otherAnswer.value)) { + if (otherCheckbox.value && otherCheckbox.value.checked && !answerArr.value.includes(otherAnswer.value)) { answerArr.value.push(otherAnswer.value) } console.log(filteredAnswerArr.value) @@ -88,7 +94,7 @@ watch(filteredAnswerArr, () => { }); watch(otherAnswer, (newOtherAnswer, oldOtherAnswer) => { - if (newOtherAnswer !== oldOtherAnswer && document.getElementById("other").checked === true) { + if (newOtherAnswer !== oldOtherAnswer && otherCheckbox.value && otherCheckbox.value.checked) { const otherIndex = answerArr.value.indexOf(oldOtherAnswer); if (otherIndex !== -1) { answerArr.value.splice(otherIndex, 1); @@ -96,6 +102,7 @@ watch(otherAnswer, (newOtherAnswer, oldOtherAnswer) => { answerArr.value.push(newOtherAnswer); } }) + watch(otherAnswerChecked,() => { if(otherAnswerChecked.value) { if (!answerArr.value.includes(otherAnswer.value)) {