离子设置通过JavaScript的全局变量,带有来自API的值

发布于 2025-01-22 10:27:33 字数 1090 浏览 1 评论 0原文

我正在构建一个离子Web应用程序,并且有一个API数据源,其中包括基本主题,即:保存按钮颜色,文本颜色,背景颜色,Cancelbtn颜色等...这些目前都采用HEX格式。

我想做的是将这些价值集成到我的离子主题中。沿着:

LOCATED in variables.scss
:root {
  --ion-editBtnColor: var(editBtnColor)
  --bs-font-sans-serif: "Lato";
  --ios-font-family: "Lato";
}

LOCATED in .ts file:
themeColors = {
addSaveBtnColor: "#6bbd54"
backgroundColor: "#1f80b8"
cancelBtnColor: "#bf9a04"
editBtnColor: "#bd4639"
eventsBtnColor: "#325467"
homeBtnColor: "#42a5cf"
pageHeadingColor: "#fff111"
projectLogo: "<img style='background-color:#ffffff' src=''>"
recID: 8
textLabelColor: "#ffffff"
}

editBtnColor = themeColors.editBtnColor;

我一直发现的所有搜索/文档的内容与我为不同主题设置SCSS文件更相关,并有条件地设置主题。

我真的没有代码示例,因为我的代码当前已经添加了具有更新值的自定义类,但这并不能很好地使用Ionic。

API示例

{
addSaveBtnColor: "#6bbd54"
backgroundColor: "#1f80b8"
cancelBtnColor: "#bf9a04"
editBtnColor: "#bd4639"
eventsBtnColor: "#325467"
homeBtnColor: "#42a5cf"
pageHeadingColor: "#fff111"
projectLogo: "<img style='background-color:#ffffff' src=''>"
recID: 8
textLabelColor: "#ffffff"
}

I'm building an ionic web app and I have an API datasource which includes basic theming ie: Save button color, text color, background color, cancelBtn color, etc... these are currently in Hex format.

What I would like to do is integrate these values into my ionic theming. Something along the lines of:

LOCATED in variables.scss
:root {
  --ion-editBtnColor: var(editBtnColor)
  --bs-font-sans-serif: "Lato";
  --ios-font-family: "Lato";
}

LOCATED in .ts file:
themeColors = {
addSaveBtnColor: "#6bbd54"
backgroundColor: "#1f80b8"
cancelBtnColor: "#bf9a04"
editBtnColor: "#bd4639"
eventsBtnColor: "#325467"
homeBtnColor: "#42a5cf"
pageHeadingColor: "#fff111"
projectLogo: "<img style='background-color:#ffffff' src=''>"
recID: 8
textLabelColor: "#ffffff"
}

editBtnColor = themeColors.editBtnColor;

All searching/documentation I've been finding are more related to me setting a scss file for different themes, and conditionally setting the theme.

I don't really have a code example, as my code currently has been adding custom classes with the updated values, but that's not playing with Ionic well.

API Example

{
addSaveBtnColor: "#6bbd54"
backgroundColor: "#1f80b8"
cancelBtnColor: "#bf9a04"
editBtnColor: "#bd4639"
eventsBtnColor: "#325467"
homeBtnColor: "#42a5cf"
pageHeadingColor: "#fff111"
projectLogo: "<img style='background-color:#ffffff' src=''>"
recID: 8
textLabelColor: "#ffffff"
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文