TotoList.js 1.64 KB
Newer Older
mayi's avatar
mayi committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
import React, { Component } from "react";
import { CHANGE_INPUT,ADD_ITEM,DELETE_ITEM} from "./store/actionsTypes";
import store from "./store/index";
import TotoListUI from './TotoListUI'
// import axios from 'axios'
// const https = 'https://www.easy-mock.com/mock/5cfcce489dc7c36bd6da2c99/xiaojiejie/getList'


// const Arrdata = ["kong"];
class TotoList extends Component {
  constructor(props) {
    super(props);
 
    this.state = store.getState();
    console.log(store.getState());
    // this.changeInputValue = this.changeInputValue.bind(this)
    //  this.storeChange = this.storeChange.bind(this);
  }
 
  storeChange() {
    this.setState(store.getState());
  }
  changeInputValue(e) {
    // console.log(e.target.value)
    const action = {
      type: CHANGE_INPUT,
      value: e.target.value,
    };

    store.dispatch(action);
  }
  addValue() {
    // console.log("dianjile ");
    const action = {
      type: ADD_ITEM,
    };
    store.dispatch(action);
  }
  deleteItem(index) {
    // console.log(index)
    const action = {
      type: DELETE_ITEM,
      index,
    };
    store.dispatch(action);
  }
  componentDidMount() {
    store.subscribe(() => {
      console.log("change",store.getState())
      this.storeChange();
    });
    // axios.get('https://www.easy-mock.com/mock/5cfcce489dc7c36bd6da2c99/xiaojiejie/getList').then((res) =>{
    //   console.log(res)
    // })
  }
  render() {
    return (
      <TotoListUI
      inputValue={this.state.inputValue}
      changeInputValue={this.changeInputValue}
      addValue={this.addValue}
      list={this.state.list}
      deleteItem={this.deleteItem}
      />
    );
  }
}
export default TotoList;