<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之旅 廣告
                app.js ~~~ import React, { Component } from 'react'; import store from '../store/index.js'; class App extends Component { //動態顯示時數據 構造器 constructor(props) { super(props); console.log(store.getState()) this.state = store.getState(); // 只要store的狀態改變就會觸發(要通過事件獲取reducer中的數據,多個數據時也只使用一個) store.subscribe(this.handleStoreChange) } // 固定格式返回一個html1 render() { return ( <div> <input value={this.state.inputValue} onChange={this.handleChange}/> <button onClick={this.handleAdd}>添加</button> <div> {this.state.list.map((value,index)=>{ return( <div onClick={()=>{this.handleDelete(index)}} key={index}> {value} </div> ) })} </div> </div> ); } handleChange = (e) => { const action ={ type:'inputChange', value:e.target.value } store.dispatch(action); } handleStoreChange=()=> { this.setState(store.getState()) } handleAdd=()=>{ const action ={ type:'addItem', value:this.state.inputValue } store.dispatch(action); } handleDelete=(index)=>{ const action ={ type:'deleteItem', index } store.dispatch(action); } }; export default App; ~~~ src>store>reducer.js ~~~ // 相當于倉庫 const defaultState={ inputValue:'hello world', list:[] }; /* state指store中的數據 */ export default (state=defaultState,action)=>{ console.log(action); if(action.type==='inputChange'){ //解構復制一份 let newState = {...state} newState.inputValue = action.value; return newState; } if(action.type==='addItem'){ //解構復制一份 let newState = {...state} newState.list.push(action.value); return newState; } if(action.type==='deleteItem'){ let newState = {...state} newState.list.splice(action.index,1); return newState; } return state; } ~~~ src>store>index.js ~~~ import {createStore} from 'redux'; import reducer from './reducer'; const store = createStore(reducer,window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__()); export default store; ~~~
                  <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>

                              哎呀哎呀视频在线观看