[英]Assign background-image as variable in vuejs
I have got a vue.js component with a div.icon
: 我已经得到了一个vue.js组件
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 }}
. 虽然它易于使用
{{ name }}
,但我不知道如何传递{{ 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? 我怎样才能使用道具:
img
来分配背景图像?
使用此问题中的 “background-image”:
v-bind:style="{ 'background-image': 'url(' + img + ')' }"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.