1

普通样式名称使用 —— className

app.css

.c1{
    color: red;
    width: 100%;
    height: 300px;
    border: solid 1px red;
}

app.js

import './app.css'

import React from 'react';
import ReactDOM from 'react-dom';

import './modules/cp/cp.scss'
class Component1 extends React.Component{
    render(){
        return (
            <div className="c1"></div>
        )        
    }
}

ReactDOM.render(
    <Component1 />,
    document.getElementById('app')
)

行内样式

let c1 = {
    color: 'red',
    width: '100%',
    height: '300px',
    border: 'solid 1px red'
}
class Component1 extends React.Component{
    render(){
        console.log(c1)
        return (
            <div style={c1}></div>
        )        
    }
}

DK_Lan
340 声望253 粉丝

前端高级讲师,附上本人随堂视频:[链接]