工程结构和模块化
创建组件
在src目录下新建目录components
,如果要创建Hello
组件,便创建文件夹Hello
,创建文件
index.jsx
index.css
CSS样式模块化
为了防止组件之间的样式冲突,可以在组件文件下的样式文件index.css
改为index.module.css
文件,这样原本的导入语句:
import "./index.css"
就可以改为:
import hello from "./index.css"
// 在使用时,就不可直接使用css样式名称了
<h1 className={hello.title}></h1>
最后更新于
这有帮助吗?