hakonbja
(Hákon Bjarnason)
1
你好,
过去一周左右,我一直在为一个品牌定制 Discourse 设置,包括固定字体、徽标和图标。
起初我注意到,任何我导入的资源(放入 assets 文件夹并在 about.json 的 assets 对象下导入)都会立即作为 SCSS 变量可用,但需要一两分钟才会出现在 settings.theme_uploads 中。
但现在,它们根本不会出现在 settings.theme_uploads 中,这意味着我无法在 JavaScript 中使用它们。如果我删除某个资源,它仍然会保留在设置对象中。SCSS 的使用不受影响。
非常感谢您的帮助。
是的,我也对这个问题有点困惑。
什么时候可以在 JavaScript 中安全地使用诸如 return settings.theme_uploads.blah 这样的引用,如果可以的话?
在我的计算属性中,我得到 settings.theme_uploads 为“undefined”(至少一开始是这样)。
这里的正确模式是什么?
david
(David Taylor)
3
settings.theme_uploads 数据是最近才添加到 javascript 中的(我认为是在 OP 编写之后)。它应该是可靠的——我们在自己的主题/组件中也使用它。你能更详细地解释一下你遇到的问题吗?
Ah, I was missing the assets folder in my path to the asset, so the broken link had “optimised out” the asset no doubt:
{
"name": "Cool Theme Component",
"about_url": "",
"component": true,
"assets": {
"background": "background.png"
}
}
should have been:
{
"name": "Cool Theme Component",
"about_url": "",
"component": true,
"assets": {
"background": "assets/background.png"
}
}
Doh!
FYI I’m reference this in Javascript in an Ember Component, e.g.:
@computed
backgroundImage() {
return settings.theme_uploads.background;
}
That would raise an undefined error when the path is incorrect!
Thanks for listening! @david, sorry to waste your time.
@hakonbja did you solve your issue?