VueJS v-bind:background-image的样式:url() [英] VueJS v-bind:style for background-image: url()

查看:1137
本文介绍了VueJS v-bind:background-image的样式:url()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据 VueJS docs:


< ; 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 样式无效属性。

But the results are not valid for the HTML style attribute.

任何想法?

推荐答案

尝试其他后模式,这是有效的:

After trying other patterns, this is the one that works:

< div v-bind:style ='{backgroundImage:url(+ item。 img +),}'>< / div>

结果:

< div style ='{background-image:url(/ img / path / img.jpg),}'>< / div>

这篇关于VueJS v-bind:background-image的样式:url()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆