1行内样式-style
<h1 style={{color:"red",backgroundColor:"skyblue"}}>
jsx的样式处理
</h1>
2类名----className(推荐)
<h1 className="title"></h1>
//导入react import React from "react" import ReactDOM from "react-dom" //第一步创建jsx创建react元素 // const fangfang=<p>我是方方</p> // const name="geyao" // const sayHi=()=>"geyao" // const title =(<h1> // <p className={{color:"red"}}>hello {name}</p> // <p>{sayHi()}</p> // <p>{1}</p> // {fangfang} // </h1>) const songs=[ {id:1,name:"geyao"}, {id:2,name:"fangfang"}, {id:1,name:"nannan"} ] const isLoading=true const lodingData=()=>{ if(isLoading){ return <div>loading...</div> } return <div>数据加载完成,此处显示加载后的数据</div> } const list=( <ul> {songs.map(item=>(<li style={{color:"red", backgroundColor:"skyblue"}} key={item.id}>{item.name}</li>))} </ul> ) const title=( <div> 条件渲染: {lodingData()} {list} </div> ) //第二步渲染React元素 ReactDOM.render(title,document.getElementById("root"))
运行结果