1. 程式人生 > >React 學習筆記 (一)(建立元件、繫結資料、繫結屬性、迴圈資料、引入圖片)

React 學習筆記 (一)(建立元件、繫結資料、繫結屬性、迴圈資料、引入圖片)

使用 create-react-app 快速構建 React 開發環境

$ cnpm install -g create-react-app
$ create-react-app my-app
$ cd my-app/
$ npm start

建立元件、繫結資料、繫結屬性、迴圈資料

在這裡插入圖片描述
在這裡插入圖片描述
引入圖片
引入圖片
react引入圖片
注意的點:
1、所有的模板要被一個根節點包含起來
2、模板元素不要加引號
3、用大括號{}繫結資料
4、迴圈資料要加key
5、img要加alt
6、繫結屬性
class 要變成 className
for 要變成 htmlFor
style屬性寫法

<div style={{'color':'red'}}>行內樣式1雙大括號</div>
<div style={this.state.style}>行內樣式2  style="{'{this.state.style}'}"</div>