The background image that is dynamically added to the div after the resource is requested in vue, why can't it be displayed?

data(){
    return {
        bg:""
    }
}

the requested resource can be added to the bg, but the div has width and height even if it is not shown.

Feb.27,2021

The

code is fine. I think the picture should be out, but it's in the wrong position. You can try it like this

.
<div v-if="bg" :style="{'background':'url('+bg+')center center;'}"></div>

the width and height of bigBg are set in advance


looks normal, but you can console your url to see if the path is correct.


I return the link at the back end of uploading the image locally, and then add it to the background of div. There is nothing wrong with using backgroundImage. There may be a delay. When assigning to the background, adding a setTimeout, will work

.
Menu