我如何在React中正确运行CSS负载?

时间:2019-05-24 00:00:06

标签: javascript reactjs css-loader

我正在学习反应,并且试图在我的个人项目中添加一些CSS。我正在搜索它,但发现了几种方法:

javascript

npm run eject 
// and modifi the path [name]__[local]__[]

import Classes from '.../css/style.css'
//using this method

<link rel="stylesheet" src="./css/styles.css">
// in HTML file 

//adding react glamor

哪种方法是正确的?

1 个答案:

答案 0 :(得分:0)

例如,您仅导入组件

import './my-style.css'

,并且在组件jsx中通常调用clasname

<div className="my-class-css">
   ...
</div>

赞:

import React, {Component} from 'react';
import './my-style.css'
class MyComponent extends Component{
    render(){
        return(
            <div className="my-class-css">
                ....
            </div>
        )
    }
}

export default MyComponent;