我有一个带有 div.icon
的 vue.js 组件:
Vue.component('obj', {
props: ['img', 'name'],
template: '<div><div class="icon"></div> {{ name }}</div>'
})
虽然 {{ name }}
很容易使用,但我不知道如何传递 {{ img }}
。
我尝试添加以下代码,但不起作用:
v-bind:style="{ backgroundImage: 'url(' + {{ img }} + ')' }"
如何使用 Prop :img
来分配背景图像?
最佳答案
使用 this issue 中的“背景图像” :
v-bind:style="{ 'background-image': 'url(' + img + ')' }"
关于javascript - 在 vuejs 中将背景图像分配为变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44791072/