根据 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
属性。
有什么想法吗?
最佳答案
尝试其他模式后,这是有效的模式:
<div v-bind:style='{ backgroundImage: "url(" + item.img + ")", }'></div>
结果:
<div style='{ background-image: url("/img/path/img.jpg"), }'></div>
关于javascript - VueJS v 绑定(bind) :style for background-image: url(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40666716/