css module 是作用域样式。样式文件与组件一一对应,借助构建工具,可以将类名改为与组件绑定的新的名称。
css module 可以解决css样式全局冲突问题。
<h1 class="title">An example heading</h1>.title {background-color: red;}
使用 css module
import styles from "./styles.css";element.innerHTML =`<h1 class="${styles.title}">An example heading</h1>`;
编译为
<h1 class="_styles__title_309571057">An example heading</h1>._styles__title_309571057 {background-color: red;}
使用css module 之后我们可以不在使用 BEM规范,这样类名看起来也更清晰。
