I am making a weather app but don't understand why my code doesn't change background image.
Codepen of app: https://codepen.io/Link0w0/pen/ZEeBaOj
Code I added to change background:
<div id="app" :class="typeof weather.main != 'undefined' && weather.main.temp > 16 ?
'warm' : ''">
#app.warm {
background-image: url('https://images.unsplash.com/photo-1581205135021-fbad89f942a6?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=2894&q=80')
background-size: cover;
background-position: bottom;
}
weatheravailable when you load the component? If not, it will crash trying to access the property main of undefined, and never change your class. For complex checks like this it is better to take this JS code out of your template and into a computed property that computes the class, you'll have more control that way.<div id="app" class="warm">, it seems the class isn't applied to the tag.warmclass doesn't update the CSS...</div>tag is on the wrong position. Take a look at my answer