I have implemented a method in Vue that toggles the darkMode variable when clicked. However, I'm facing an issue where it always triggers both the if and else parts of the method.
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
}
}
}
The expected output is for the first click to log "should be dark" and the second click to log "should be light". However, it is currently triggering both log statements on each click.
I am aware that it works correctly with "else if", but I'm confused as to why it doesn't work this way.