<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                [TOC] `npm i redux -s`或`yarn add redux` ~~~ 在chrome商店中安裝redux ~~~ 目錄結構 ![](https://box.kancloud.cn/a44f86985ab1910fa28f78035f9d34e6_207x294.png) ## 1.定義store管理哪些數據 ``` import {createStore} from 'redux'; ``` ## 2.定義reducer放置數據 ``` var defaultState={ inputValue:"hello world", list:[] } export default (state=defaultState,action)=>{ if(action.type==="inputChange"){ var newState = {...state}; newState.inputValue = action.value; return newState; } return state; } ``` ## 3.將reducer中的數據和store通信 ``` import reducer from './reducer'; const store = createStore(reducer,window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__()); export default store; ``` ## 4.在app.js中用使用store中的數據 ``` import store from './store/index.js'; class App extends Component { constructor(props){ super(props); this.state = store.getState() } } ``` ## 5.事件派發action給store ``` handleChange=(event)=>{ var action ={ type:"inputChange", value:event.target.value } store.dispatch(action); } ``` ## 6.在reducer中改變state ``` var defaultState={ inputValue:"hello world", list:[] } export default (state=defaultState,action)=>{ if(action.type==="inputChange"){ var newState = {...state}; newState.inputValue = action.value; return newState; } return state; } ``` ## 7.組件訂閱store的改變 ``` constructor(props){ super(props); this.state = store.getState() /* 只要store的狀態發生改變的時候就會觸發 */ store.subscribe(this.handleStoreChane) } handleStoreChane=()=>{ this.setState(store.getState()) } } ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看