I have the simplest method and I have used this method many times before, but even though I used the same method, it doesn't work in the component I'm working on right now. Here is what I want;
I have two checboxes;
<input type="checkbox" class="blacklist" v-model="blacklist" @change="listChanger();"/>
<input type="checkbox" class="whitelist" v-model="whitelist" @change="listChanger();"/>
My data;
data() {
return {
whitelist: false,
blacklist: false,
};
},
They are set as closed at the default state. When they are turned to true, they show some div
on the page;
<div v-if="blacklist">
something something...
</div>
<div v-if="whitelist">
something something...
</div>
The thing is that whitelist
and showlist
cannot be true at the same time, in other words, their divs cannot be visible at the same time. When one of them is true, the other one should be false automatically. Here is my method to do that;
METHODS UPDATED:
listChanger(){
if(this.whitelist == true){
this.blacklist = false;
}
else if(this.blacklist == true){
this.whitelist = false;
}
},
The above method is working when you first check blacklist
, then check whitelist
. The method is being triggered by the checkboxes so when blacklist is true first, then whitelist is true, the method goes and unchecks the blacklist as it should be. But the other scenario still off.
Let's say I checked the blacklist
first, then I go and checked whitelist
, I want blacklist to be closed, and whitelist to be visible. The same scenario is also needed when whitelist
is checked first. I know I'm missing some little things here but I couldn't figure. I tried to use the if
statements in the updated()
hook, it works but once one of them is turned to false, I cannot use that one again, I mean it's not clickable anymore because the other one is true. As long as one of them is true, it does not let me click the other one. My question is simple but I couldn't figure it out yet so any help would be appreciated.