Laravel & React 4
Bu bölümde axios ile api ya ulaşıp http istekleri yapacağız. Yeni bir component oluşturup. Constructarda bir initial state tanımlayıp componentwillMount yaşam döngüsü ile state mizi dolduracağız. D:\WorkSpace\Tutorals\Laravel\react-lara> npm install axios --save Komutu ile öncelikle projemize axios kütüphanesini dahil ediyoruz. Ardından yeni bir component oluşturuyoruz. Constructor methodumda initState yi tanımlıyorum. constructor (){ super (); this .state = { blog :[] } console . log ( super ()); } ardından Componentwillmount ile apimıza istek atacağız. Bu method hem server hemde client oluşturulmadan önce çalıştırılır. ComponentDidMount ise ilk çalışmanın ardından sunucu tarafından çalıştırılır. componentWillMount () { axios . get ( '/api/blog' ). then ( response => { this . setState ({ blog : response .data }) }). catch ( err => { ...
Yorumlar
Yorum Gönder