1

Background image not applying to this div when i was calling changeBgImage function on load.I searched through the web but not getting the desired result.Please help me

<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)

}

1 Answer 1

2

You have to add width and height to the tag (or container)

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

<div 
  :style="{ background: `url(${imageUrl}) no-repeat center` }" 
  style="width: 350px; height: 150px"
>
</div>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.