做爰高潮a片〈毛片〉,尤物av天堂一区二区在线观看,一本久久A久久精品VR综合,添女人荫蒂全部过程av

最新文章專題視頻專題問答1問答10問答100問答1000問答2000關鍵字專題1關鍵字專題50關鍵字專題500關鍵字專題1500TAG最新視頻文章推薦1 推薦3 推薦5 推薦7 推薦9 推薦11 推薦13 推薦15 推薦17 推薦19 推薦21 推薦23 推薦25 推薦27 推薦29 推薦31 推薦33 推薦35 推薦37視頻文章20視頻文章30視頻文章40視頻文章50視頻文章60 視頻文章70視頻文章80視頻文章90視頻文章100視頻文章120視頻文章140 視頻2關鍵字專題關鍵字專題tag2tag3文章專題文章專題2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章專題3
問答文章1 問答文章501 問答文章1001 問答文章1501 問答文章2001 問答文章2501 問答文章3001 問答文章3501 問答文章4001 問答文章4501 問答文章5001 問答文章5501 問答文章6001 問答文章6501 問答文章7001 問答文章7501 問答文章8001 問答文章8501 問答文章9001 問答文章9501
當前位置: 首頁 - 科技 - 知識百科 - 正文

用react-redux實現(xiàn)react組件之間數(shù)據(jù)共享的方法

來源:懂視網(wǎng) 責編:小采 時間:2020-11-27 22:13:15
文檔

用react-redux實現(xiàn)react組件之間數(shù)據(jù)共享的方法

用react-redux實現(xiàn)react組件之間數(shù)據(jù)共享的方法:上篇文章寫到了redux實現(xiàn)組件數(shù)據(jù)共享的方法,但是在react中,redux作者提供了一個更優(yōu)雅簡便的模塊實現(xiàn)react組件之間數(shù)據(jù)共享。那就是利用react-redux 利用react-redux實現(xiàn)react組件數(shù)據(jù)之間數(shù)據(jù)共享 1.安裝react-redux $ npm i
推薦度:
導讀用react-redux實現(xiàn)react組件之間數(shù)據(jù)共享的方法:上篇文章寫到了redux實現(xiàn)組件數(shù)據(jù)共享的方法,但是在react中,redux作者提供了一個更優(yōu)雅簡便的模塊實現(xiàn)react組件之間數(shù)據(jù)共享。那就是利用react-redux 利用react-redux實現(xiàn)react組件數(shù)據(jù)之間數(shù)據(jù)共享 1.安裝react-redux $ npm i

上篇文章寫到了redux實現(xiàn)組件數(shù)據(jù)共享的方法,但是在react中,redux作者提供了一個更優(yōu)雅簡便的模塊實現(xiàn)react組件之間數(shù)據(jù)共享。那就是利用react-redux

利用react-redux實現(xiàn)react組件數(shù)據(jù)之間數(shù)據(jù)共享

1.安裝react-redux

$ npm i --save react-redux

2.從react-redux導入Prodiver組件將store賦予Provider的store屬性,

將根組件用Provider包裹起來。

import {Provider,connect} from 'react-redux'
ReactDOM.render(
<Provider store={store}>
 <Wrap/>
</Provider>,document.getElementById('example'))

這樣根組件中所有的子組件都可以獲得store中的值

3.connect二次封裝根組件

export default connect(mapStateToProps,mapDispatchToProps)(Wrap)

connect接收兩個函數(shù)作為參數(shù),一個mapStateToProps定義哪些store屬性會被映射到根組件上的屬性(把store傳入react組件),一個mapDispatchToProps定義哪些行為action可以作為根組件屬性(把數(shù)據(jù)從react組件傳入store)

3.定義這兩個映射函數(shù)

function mapStateToProps(state){
 return {
 name:state.name,
 pass:state.pass
 }
}
function mapDispatchToProps(dispatch){
 
 return {actions:bindActionCreators(actions,dispatch)
 }
}

把store中的name,pass映射到根組件的name,pass屬性。

actions是一個包含了action構建函數(shù)的對象,用bindActionCreators把對象actions綁定到根組件actions屬性上。

4.在根組件引用子組件的位置用 <Show name={this.props.name} pass={this.props.pass}></Show>將store數(shù)據(jù)傳入子組件.

5.在子組件中調用actions中的方法來更新store中的數(shù)據(jù)

<Input actions={this.props.actions} ></Input>

先將actions作為屬性傳入子組件

子組件調用actions中的方法創(chuàng)建action

//Input組件
export default class Input extends React.Component{
sure(){
this.props.actions.add({name:this.refs.name.value,pass:this.refs.pass.value})
}
 render(){ 
 return (
 <div> 
 姓名:<input ref="name" type="text"/>
 密碼:<input ref="pass" type="text"/>
 <button onClick={this.sure.bind(this)}>登錄</button>
 </div>

 )
 }
}

因為我們采用了bindActionCreators函數(shù),創(chuàng)建action后會立即自動調用store.dispatch(action)將數(shù)據(jù)更新到store.

這樣我們就利用react-redux模塊完成了react各個組件之間數(shù)據(jù)共享。

跟上篇文章一樣,實現(xiàn)了在一個組件Input中通過actions更新數(shù)據(jù)到store,然后在另一個組件Show中展示store中的數(shù)據(jù)

聲明:本網(wǎng)頁內容旨在傳播知識,若有侵權等問題請及時與本網(wǎng)聯(lián)系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

文檔

用react-redux實現(xiàn)react組件之間數(shù)據(jù)共享的方法

用react-redux實現(xiàn)react組件之間數(shù)據(jù)共享的方法:上篇文章寫到了redux實現(xiàn)組件數(shù)據(jù)共享的方法,但是在react中,redux作者提供了一個更優(yōu)雅簡便的模塊實現(xiàn)react組件之間數(shù)據(jù)共享。那就是利用react-redux 利用react-redux實現(xiàn)react組件數(shù)據(jù)之間數(shù)據(jù)共享 1.安裝react-redux $ npm i
推薦度:
標簽: 使用 組件 React
  • 熱門焦點

最新推薦

猜你喜歡

熱門推薦

專題
Top
主站蜘蛛池模板: 达日县| 华蓥市| 定边县| 韶山市| 上饶市| 论坛| 永登县| 印江| 鄂州市| 思茅市| 阿巴嘎旗| 英德市| 盐源县| 呼玛县| 吉安县| 利辛县| 克山县| 崇明县| 射阳县| 游戏| 敖汉旗| 达拉特旗| 游戏| 娱乐| 平利县| 南部县| 平南县| 常宁市| 深圳市| 逊克县| 临夏县| 化州市| 安徽省| 肃宁县| 古浪县| 东兰县| 宜城市| 延边| 华坪县| 濮阳市| 大丰市|