根据 VueJS
文档:
<div v-bind:style="{ color: activeColor, fontSize: fontSize + 'px' }"></div>
我尝试了几种模式:
<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>
但结果对 HTML style
属性无效。
有任何想法吗?
原文由 Gus 发布,翻译遵循 CC BY-SA 4.0 许可协议
尝试其他模式后,这是有效的模式:
<div v-bind:style='{ backgroundImage: "url(" + item.img + ")", }'></div>
结果是:
<div style='{ background-image: url("/img/path/img.jpg"), }'></div>