React 教程第六篇 —— 样式绑定

普通样式名称使用 —— 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
    原文地址: https://segmentfault.com/a/1190000014989264
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞