I had problems with this because there are quotes around the inline style, and then two more sets of quotes in 'url("")'
. When I pulled the style object into my object, I got it:
https://jsfiddle.net/ahwLc3rq/
HTML
<div id="app"> <div id="test" :style="backgroundStyle"></div> </div>
Js
new Vue({ el:'#app', data:function(){ return { pic_url: 'https://anchormetrics.com/wp-content/themes/bootstrap-basic-child/images/amlogo.png' } }, computed:{ backgroundStyle:function(){ return { 'background-image':'url("'+this.pic_url+'")' } } }, methods:{ fetchPic:function(){ this.$http.get('/path/to/api').then(function(response){ this.pic_url = response; }.bind(this)) } }, ready:function(){ this.fetchPic(); } });
source share