Reputation: 75
In Vuetify's v-list-item directive I can't remove the active prop once an item has been selected. So far this is what I have tried:
<v-list-item-group pb-6 color="primary" class="pb-3 text-left">
<v-list-item v-for="(answer, index) in answers" :key="index">
<v-list-item-title :class="{ active: isActive }" v-text="answer" @click.prevent="selectAnswer(index)">
</v-list-item-title>
</v-list-item>
</v-list-item-group>
<b-button variant="primary" :disabled="hasAnswered" @click="submitAnswer()">
Submit
</b-button>
export default {
name: 'QuestionBox',
data () {
return {
answers: '',
selectedIndex: null,
hasAnswered: false,
isActive: undefined
}
},
methods: {
selectAnswer (ind) {
this.isActive = true
this.selectedIndex = ind
},
submitAnswer () {
this.hasAnswered = true
this.isActive = false
}
}
}
I know the :class="{ active: isActive }"
will apply to the v-list-item-title, but the v-list-item has the v-for so anyone has any ideas?
Upvotes: 2
Views: 8505
Reputation: 35704
You can do that by using the v-model
Calling clear
method from examples will clear the selection
<v-list-item-group v-model="selection">
data: () => ({
selection: null
}),
methods:{
clear(){ this.selection = null }
}
<v-list-item-group v-model="selection" multiple>
data:() => ({
selection: []
}),
methods:{
clear(){ this.selection = [] }
}
Upvotes: 5