來自乙個react SPA的總結 es6的應用

2021-07-14 10:51:03 字數 1380 閱讀 8961

這篇主要總結一些,es6在react中的應用,並沒有囊括所有,只是總結一些本人平常沒有理解的知識點………..

1.es6 arrow functions

es6的箭頭函式在這個簡單project中用到多次,下面以乙個對比**塊展示一下:

// old way with es5

componentdidmount: function

() );

});},// new way with es6 arrow functions

componentdidmount: function

() );

});}

2.es6 spread operator

在這個project中,使用es6的解構賦值來給component傳遞引數,下面通過**段來展示這種用法:

假設我們想從parent component傳遞乙個物件給child component:

// parent component's render method

render: function

() ;

return (user= />);

}

通過這種user=的方式傳遞資料,如果子元件想要獲得name這個資料,就需要通過this.props.user.name的方式獲取資料,看下面這種方式

// parent component's render method

render: function

() ;

return (name=

occupation=

state= />);

}

這種方式,子元件想要獲得name或全部資料,需要this.props.name,前提是要像這樣name= occupation= state=哦,也是挺麻煩的,所以使用es6的特性之一,解構賦值方便了許多哦!看下面的**塊:

// parent component's render method

render: function

() ;

return ();

}

這樣,子元件只需要this.props.name,this.props.occupation,this.props.state方式就能獲得傳遞過來的資料了

更詳細的請看react官方文件spread attributes

來自乙個react SPA的總結 redux篇

本文是自己這幾天做乙個reactspa的其中之一篇總結,主要總結在實踐中,學習到的有關redux的一些思想 並沒有太多細節 方便日後自己的重溫 redux用作管理應用的data state和ui state,在react中元件間的通訊一般是parent child間,兄弟間鑑於我初出茅廬,暫時沒遇到...

來自HPE的乙個渣渣學生的總結

物理終端 直接接入本機的顯示器和鍵盤裝置 虛擬終端 附加在物理終端之上的以軟體方式虛擬實現的終端 centos 6預設啟動6個虛擬終端 使用ctrl alt f1 f6 檢視當前的終端裝置 tty 檢視當前使用的shell echo shell 作業系統 靜態資料鏈結庫 動態資料鏈結庫 window...

來自乙個前端新手的感悟

初入社會,我只是乙個前端路上飛行的菜鳥,經過一段時間的工作之後,才知道,我踩了無數的坑。希望,看過我寫的文章的同胞們,不要再和我犯同樣的錯誤。純屬個人思考 1.當負責專案中乙個模組的開發時,不要忘記,它只是專案中的乙個模組。當我拿到專案經理安排好的工作計畫書時,開始對自己負責的部分的需求進行熟悉,這...