Marian Rick
Marian Rick

Reputation: 3440

Assign background-image as variable in vuejs

I have got a vue.js component with a div.icon:

Vue.component('obj', {
  props: ['img', 'name'],
  template: '<div><div class="icon"></div> {{ name }}</div>'
})

While its easy to use {{ name }}, I do not know how to pass {{ img }}.

I have tried to add the following code, which does not work:

v-bind:style="{ backgroundImage: 'url(' + {{ img }} + ')' }"

How can I use the props: img to assign a background-image?

Upvotes: 1

Views: 1093

Answers (1)

Blue
Blue

Reputation: 22911

Use 'background-image' from this issue:

v-bind:style="{ 'background-image': 'url(' + img + ')' }"

Upvotes: 4

Related Questions