在 vuejs 中将背景图像分配为变量
Assign background-image as variable in vuejs
我有一个 vue.js 组件 div.icon
:
Vue.component('obj', {
props: ['img', 'name'],
template: '<div><div class="icon"></div> {{ name }}</div>'
})
虽然好用{{ name }}
,但不知道怎么传{{ img }}
。
我已尝试添加以下代码,但不起作用:
v-bind:style="{ backgroundImage: 'url(' + {{ img }} + ')' }"
如何使用道具:img
分配背景图像?
使用 this issue 中的 'background-image':
v-bind:style="{ 'background-image': 'url(' + img + ')' }"
我有一个 vue.js 组件 div.icon
:
Vue.component('obj', {
props: ['img', 'name'],
template: '<div><div class="icon"></div> {{ name }}</div>'
})
虽然好用{{ name }}
,但不知道怎么传{{ img }}
。
我已尝试添加以下代码,但不起作用:
v-bind:style="{ backgroundImage: 'url(' + {{ img }} + ')' }"
如何使用道具:img
分配背景图像?
使用 this issue 中的 'background-image':
v-bind:style="{ 'background-image': 'url(' + img + ')' }"