I have two checkboxes in Vuetify. I’m trying to write them in a way that if I check checkbox A, it automatically checks both checkbox A & B. But clicking on checkbox B triggers only checkbox B. What’s the best way to do it? Here is my code:
JavaScript
x
4
1
<v-checkbox label="A" value="A" v-model="A"> </v-checkbox>
2
3
<v-checkbox label="B" value="B" v-model="B"></v-checkbox>
4
Advertisement
Answer
There are few solutions to handle it.
- You can use Vue watch
JavaScript120201<template>
2<div>
3<v-checkbox label="A" v-model="A"> </v-checkbox>
4<v-checkbox label="B" v-model="B"></v-checkbox>
5</div>
6</template>
7<script>
8export default {
9
10watch: {
11A: function (newVal) {
12if (newVal) {
13this.B = true
14}
15}
16}
17
18}
19</script>
20
- Using
@change
event onv-checkbox