Answer the question
In order to leave comments, you need to log in
How can I make sure that only one checkbox is selected?
Good afternoon, how can I make sure that only one checkbox is ticked when clicked, and the rest of the checkboxes are unchecked. Thanks in advance
<div id="app">
<input type="checkbox" id="jack" value="Джек" v-model="checkedNames">
<label for="jack">Джек</label>
<input type="checkbox" id="john" value="Джон" v-model="checkedNames">
<label for="john">Джон</label>
<input type="checkbox" id="mike" value="Майк" v-model="checkedNames">
<label for="mike">Майк</label>
<br>
<span>Отмеченные имена: {{ checkedNames }}</span>
</div>
<script>
new Vue({
el: '#app',
data: {
checkedNames: []
}
})
</script>
Answer the question
In order to leave comments, you need to log in
data: () => ({
checked: null,
items: [ 'hello, world!!', 'fuck the world', 'fuck everything' ],
}),
<label v-for="(n, i) in items">
<input
type="checkbox"
:checked="checked === i"
@change="checked = $event.target.checked ? i : null"
>
{{ n }}
</label>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question