According to VueJS
docs:
<div v-bind:style="{ color: activeColor, fontSize: fontSize + 'px' }"></div>
I've tried several patterns:
<div v-bind:style="{ background-image: url(item.img), }"></div>
<div v-bind:style="{ 'background-image': url('item.img'), }"></div>
<div v-bind:style='{ backgroundImage: "url(item.img)", }'></div>
But the results are not valid for the HTML style
attribute.
Any ideas?
based on @T.Abdullaev's answer, this one with extra double quote worked for me.
Do this. It works also for templates.
After trying other patterns, this is the one that works:
<div v-bind:style='{ backgroundImage: "url(" + item.img + ")", }'></div>
Results in:
<div style='{ background-image: url("/img/path/img.jpg"), }'></div>
Using a computed property works very well, and is cleaner: