I have an easy question for which I hope you could help:
Use a computed property for this:
...
data () {
return {
item: {
featured_photo: null
}
}
},
computed: {
background () {
return !item.featured_photo ? '#fff' : `url(${item.featured_photo}) center no-repeat`
}
},
methods: {
setPhoto(val) {
this.item.featured_photo = val
}
}
Edit:
I'm making a bunch of assumptions here with your API and routes. This is a rough stab at generalizing it:
...
methods: {
async getBackground (type, index) {
let r = await axios.get(`/images/${type}/${index}`).then(r => r.data.background)
return r || '#fff'
}
}