I am trying to toggle a class based on isNight
's truth value:
<div :class="['app-bg', { nightBg: isNight }]"></div>
I have the isNight
prop set to false as shown:
export default {
name: 'Result',
data(){
return {
error: null,
weather: null,
weatherIcon: null,
isNight: false
}
},
. . .
I have a function in computed that returns a true or false based on some data:
computed: {
nightChecker() {
return this.weatherIcon.slice(2) == 'n' ? true : false
}
},
How do I update the isNight
prop to reflect the return value of nightChecker()
? I tried isNight: nightChecker
, but that throws an error.
EDIT: Thank you to everyone who helped me understand this more. As you may can tell, I am new to Vue and am still wrapping my head around it.