react 基礎學習

2021-08-19 15:12:00 字數 1023 閱讀 2443

$ npm start                            //啟動專案

class clock extends react.component ;

}componentdidmount()

componentwillunmount()

render()

} //把元件裝進 root

reactdom.render(

,document.getelementbyid('root')

);

render()
方法1:在標籤的 onclick把 event 傳入要執行的方法  >

);方法2:在構造方法 constructor 裡 加上 bind     this.handlechange = this.handlechange.bind(this);constructor(props) ;

this.handlechange = this.handlechange.bind(this);

} handleclick())

console.log(this.state.selectvalue)

} render()

}這裡有個要注意的點就是

1、在 迴圈的 html 裡加上乙個唯一的 key ,不然會報錯

2、 list 方法要寫在元件的外面

function list(props)

) return (

)}  render()

constructor(props) ;

this.handlechange = this.handlechange.bind(this);

this.selectchange = this.selectchange.bind(this);

}handlechange(e)) }

selectchange(e)); }

render()

}

react基礎學習

最簡單的 父 子 傳值 父元件通過在子元件標籤上設定屬性傳遞資料 teachername teachername 子元件通過this.props獲取父元件傳遞的資料 this.props.teachername 獲取老師的名稱 render 我的老師是 我對老師很 滿意 button p 最簡單的 ...

react封裝函式 React 基礎學習筆記

內容 intro install page setup react elements reactdom react component react factories names abstract react.createelement reactdom.render react.component...

react 學習基礎知識

三種改變this指向的方法 1.在呼叫的時候使用bind方法 onclick 2.在constructor裡面改變this指向 this.getdata this.getdata.bind this 3.在方法上使用箭頭函式 getdata 兩種雙向繫結的方法 1.根據當前的元素自身的value值 ...