Javascript Vue js动态绑定背景图像样式不工作
当我在加载时调用Javascript Vue js动态绑定背景图像样式不工作,javascript,vuejs2,Javascript,Vuejs2,当我在加载时调用changeBgImage函数时,背景图像不适用于此div。我在网上搜索,但没有得到所需的结果。请帮助我 <div class="home_search" id="home_search" v-bind:style="{ background: `url(${imageUrl}) no-repeat center` }"> <HeaderComponent /> </div> changeBgImage () { let rand =
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)
}
更改图像(){
设rand=Math.round(Math.random()*4);
this.imageUrl=“../assets/img/home”+rand+”.jpg”;
console.log(this.imageUrl)
}
您必须为标签(或容器)添加宽度和高度
例如:
<div
:style="{ background: `url(${imageUrl}) no-repeat center` }"
style="width: 350px; height: 150px"
>
</div>