简体   繁体   English

Class 使用 Next.js 的 scss 名称约定

[英]Class names convention for scss using Next.js

Seems like an obvious question but I couldn't find good answers when googled it.似乎是一个显而易见的问题,但是当我用谷歌搜索时我找不到好的答案。 When I use scss with Next.js and import component-level scss file, is there a way of writing the name of the class with the normal css convention and then after import it to use JS convention?当我将 scss 与 Next.js 一起使用并导入组件级 scss 文件时,有没有办法用正常的 css 约定写入 class 的名称,然后在导入后使用约定? For example:例如:

 // login.module.scss file: .login-button { // some scss styling } // Login.js file: import styles from './login.module.scss' <button className={styles.loginButton}>Login</button>

Edit: I wanna do that instead of writing loginButton in my scss file because I'm rewriting my react project to Next.js and all my styling files uses 'login-button' convention.编辑:我想这样做而不是在我的 scss 文件中编写 loginButton 因为我正在将我的反应项目重写为 Next.js 并且我所有的样式文件都使用“登录按钮”约定。

The recommended convention is to use camelCase to name your css/scss classNames.推荐的约定是使用 camelCase 命名您的 css/scss 类名。 But if you still want to use kebab-case for your className, then use it with the bracket notation.但是,如果您仍然想为您的 className 使用 kebab-case,则将其与括号表示法一起使用。

/* component.module.scss */

.login-button {
  /* some scss styling */
}
// component.jsx

<button className={styles['login-button']}>Login</button>

Please follow this link to know more from the documentation.请点击此链接以从文档中了解更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM