So I have this method in vue which changes the darkMode variable onclick,
What I don't understand is why it always triggers the if part and then also triggers the else part
data(){
return{
darkMode:false,
}
},
methods:{
darkModeToggle(){
if(this.darkMode == false)
{
console.log("should be dark")
this.darkMode = true
}
else(this.darkMode == true)
{
console.log("should be light")
this.darkMode = false
}
}
}
expected output is first click = "should be dark" then second click = "should be light" However it is triggering twice on each click and outputting = "should be dark" and "should be light"
I know it works correctly with "else if" I just don't understand why it doesn't work this way.
Aucun commentaire:
Enregistrer un commentaire