简体   繁体   中英

Vue: Binding background-image style not working

In my data I have a variable called image that holds the url of my image like so: (This is the correct url as it works when I bind an image src to img tags)

data () {
   return {
     image: "../../assets/img/hk.jpg"
   } 
}

I then have this:

<div class="container" v-bind:style="{ 'background-image': 'url(' + image + ')' }">

And basically the image is not showing up. No errors in the console either. Any ideas?

image: require("../../assets/img/hj.jpg")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM