Closed as not planned
Description
Vue version
3.5.10
Link to minimal reproduction
Steps to reproduce
- Create checkbox
- Prevent default behavior by
@click.prevent=
- Change the state in the click listener
check.value = !check.value;
<script setup>
import { ref } from 'vue'
const check = ref(false);
const checkTimeout = ref(false);
function click() {
check.value = !check.value;
}
function clickTimeout() {
setTimeout(() => {
checkTimeout.value = !checkTimeout.value;
}, 1);
}
</script>
<template>
<h1>JS controlled checkbox</h1>
<p>The checkbox state does not change:</p>
<div>
<label>
<input type="checkbox" :checked="check" @click.prevent="click" />
Check: {{check}}
</label>
</div>
<p>Correct behavior:</p>
<div>
<label>
<input type="checkbox" :checked="checkTimeout" @click.prevent="clickTimeout" />
Check: {{checkTimeout}}
</label>
</div>
</template>
What is expected?
The checkbox reflects the state
What is actually happening?
The internal state of the checkbox is kept as is.
System Info
Any
Any additional comments?
Adding timeout fixes the issue:
setTimeout(() => {
checkTimeout.value = !checkTimeout.value;
}, 1);
Metadata
Metadata
Assignees
Labels
No labels