vue动态绑定背景图片
发表于:2023-09-09 08:44:32浏览:153次
<div :style="{
backgroundImage:'url('+imgurl[imgid]+')',
backgroundSize:'cover'
}"> </div>
data(){
return{
imgid:0,
imgurl:[
require("./assets/view1.jpg"),
require("./assets/view2.jpg"),
require("./assets/view3.jpg"),
]
}
}
补充:
//这里的item.img是数组循环出的图片
:style="{'background-image' : 'url(' + item.img + ')'}"
//这里的img是data中的值
:style="'background-image:' +'url('+img+')'"
//绑定背景颜色
:style="{'background-color':item.backgroundColor}"
//使用模板字符串
:style="{ 'background-image': `url(http://47.99.84.176/uploads${newsList[0].img_url})` }">
栏目分类全部>