index.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. import React from 'react';
  2. import { connect } from 'react-redux';
  3. import { BrowserRouter, Route,Link } from 'react-router-dom';
  4. import { actionCreators } from './store';
  5. class lock_count extends PureComponent {
  6. getListArea() {
  7. const { list, menu } = this.props;
  8. menu;
  9. if (true) {
  10. return (
  11. <div>
  12. {
  13. list.map((item) => {
  14. return <span className='ispan' type="text" key={item} >{item}</span>
  15. })
  16. }
  17. </div>
  18. )
  19. } else {
  20. return null;
  21. }
  22. }
  23. render() {
  24. //const { inputValue, handleInputFocus,handleInputChange, menu, list } = this.props;
  25. return (
  26. <div>lock_count</div>
  27. );
  28. }
  29. //组件即将要被挂在的时候执行的方法--
  30. componentDidMount(){
  31. //逻辑代码可以写在mapDispathToProps里 this.props.方法
  32. // axios.get('/api/submenuList.json').then((res) => {
  33. // const data = res.data;
  34. // dispatch(changeList(data.data));
  35. // }).catch(() => {
  36. // console.log('error');
  37. // })
  38. }
  39. }
  40. /**
  41. * store里的数据映射到这个组件里的state
  42. * @param {*} state
  43. */
  44. const mapStateToProps = (state) => {
  45. return {
  46. //menu: state.submenu.menu
  47. menu: state.getIn(['submenu', 'menu']),
  48. list: state.getIn(['submenu', 'list']),
  49. inputValue: state.getIn(['submenu', 'inputValue']),
  50. }
  51. // return {
  52. // focused: state.getIn(['header', 'focused']),
  53. // list: state.getIn(['header', 'list']),
  54. // page: state.getIn(['header', 'page']),
  55. // totalPage: state.getIn(['header', 'totalPage']),
  56. // mouseIn: state.getIn(['header', 'mouseIn'])
  57. // }
  58. }
  59. /**
  60. * 要改变store里的内容需要调用dispatch方法
  61. * @param {*} dispatch
  62. */
  63. const mapDispathToProps = (dispatch) => {
  64. return {
  65. handleInputFocus(list) {
  66. // const action = {
  67. // type: 'aearch_focus'
  68. // };
  69. //发送给store--提取出action--避免发送重复的ajax请求
  70. (list.size === 0) && dispatch(actionCreators.getList());
  71. // if(list.size>0){
  72. // dispatch(actionCreators.getList());
  73. // }
  74. dispatch(actionCreators.searchFocus());
  75. },
  76. handleInputChange(ivalueElem){
  77. dispatch(actionCreators.changeInputValue(ivalueElem.value));
  78. },
  79. }
  80. }
  81. export default connect(mapStateToProps, mapDispathToProps)(lock_count);