我将一个变量customPhoto传递给组件,并希望在const bg中使用它来在样式中使用。以下示例不起作用 - 我应该更改什么?
let bg = {
backgroundImage: {`url(${customPhoto})`}
};
我在代码中看到的唯一变化是在url之前和结尾处删除大括号
更改
backgroundImage: {`url(${customPhoto})`}
至
backgroundImage: `url(${customPhoto})`
你也可以做inline-css <div style={{ backgroundImage: `url(${customPhoto})` }}>