更改React中的SASS模块变量

发布于 2025-02-13 02:02:57 字数 329 浏览 0 评论 0原文

变量

$max-width: 100%;

:export {
    maxWidth: $max-width
}

具有

import styles from "../styles/Card.module.scss"

我在card.module.scss中 使用styles.maxwidth访问此值,但我不知道如何更改该值。

我知道使用css自定义属性会更容易,但是在模块中不起作用,因为它不是纯粹的选择器。

I have a variable in my Card.module.scss and use this code to export it make it available to my React components:

$max-width: 100%;

:export {
    maxWidth: $max-width
}

I import this and the rest of the styles with:

import styles from "../styles/Card.module.scss"

and I'm able to access this value using styles.maxWidth, but I don't know how to change the value.

I know it would be easier to use CSS custom properties, but that would not work in modules, as it would not be a pure selector.

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

半﹌身腐败 2025-02-20 02:02:57

我认为这实际上是不可能的:Sass是在构建中编译成常规CSS的,因此在运行时尝试修改它是没有意义的。您可能必须使用自定义属性...

如果有更多知识的人可以确认...

I don't believe it's actually possible: SaSS is compiled on build into regular CSS, so it makes no sense to try and modify it at runtime. You will probably have to use custom properties...

If anyone more knowledgable can confirm...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文