Gus*_*Gus 5 html javascript vue.js
根据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>
Run Code Online (Sandbox Code Playgroud)
但结果对HTML style属性无效.
有任何想法吗?
尝试其他模式后,这是有效的模式:
<div v-bind:style='{ backgroundImage: "url(" + item.img + ")", }'></div>
结果是:
<div style='{ background-image: url("/img/path/img.jpg"), }'></div>
根据@T.Abdullaev 的回答,这个带有额外双引号的答案对我有用。
v-bind:style='{ backgroundImage: `url("${imgUrl}")` }'
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7806 次 |
| 最近记录: |