gpt4 book ai didi

javascript - Vue js动态绑定(bind)背景图像样式不起作用

转载 作者:行者123 更新时间:2023-11-29 20:50:36 26 4
gpt4 key购买 nike

当我在加载时调用 changeBgImage 函数时,背景图像不适用于此 div。我在网上搜索但没有得到想要的结果。请帮助我

<div class="home_search" id="home_search" v-bind:style="{ background: `url(${imageUrl}) no-repeat center` }">
<HeaderComponent />
</div>

changeBgImage () {
let rand = Math.round(Math.random() * 4);
this.imageUrl = "../assets/img/home_" + rand + ".jpg";
console.log(this.imageUrl)

}

最佳答案

您必须为标签(或容器)添加宽度和高度

例子: https://codepen.io/anon/pen/vzyjww?editors=1010

<div 
:style="{ background: `url(${imageUrl}) no-repeat center` }"
style="width: 350px; height: 150px"
>
</div>

关于javascript - Vue js动态绑定(bind)背景图像样式不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52093896/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com