• App.js ```javascript import React from ‘react’; import ‘./App.css’;

    class App extends React.Component { constructor(props) { super(props); this.state = { id: 1, list: [] } } render() { return (

    ToDoList

    正在进行 {this.uncomplete()}

    {this.state.list.map(item => { return (

    {item.name}

    ) })}

    已经完成 {this.complete()}

    {this.state.list.map(item => { return (

    {item.name}

    ) })}
    Copyright © 2019 todolist.cn
    ); } handleChange(e) { var list = this.state.list var id = this.state.id if (e.keyCode === 13) { if (e.target.value !== “”) { var obj = {} obj.name = e.target.value obj.id = id id = id + 1 obj.isTodo = false list.push(obj) this.setState({ list, id }) } e.target.value = “” } } handlecheck(id) { var list = this.state.list list.forEach(item => { if (item.id == id) { item.isTodo = !item.isTodo } }) this.setState({ list }) } handledel(id){ var list = this.state.list var num = list.findIndex(item=>{ if(item.id==id){ return true } }) list.splice(num,1) this.setState({ list }) } complete(){ var list = this.state.list var sum = list.filter(item=>{ if(item.isTodo){ return true } }) return sum.length } uncomplete(){ var list = this.state.list var sum = list.filter(item=>{ if(!item.isTodo){ return true } }) return sum.length }

    } export default App;

    1. - App.css
    2. ```css
    3. *{
    4. margin: 0;
    5. padding: 0;
    6. }
    7. body{
    8. background: #CDCDCD
    9. }
    10. .logo {
    11. color: #fff;
    12. font-size: 24px;
    13. }
    14. .nav {
    15. background: #323232;
    16. height: 50px;
    17. }
    18. .nav-row {
    19. width: 600px;
    20. margin: 0 auto;
    21. display: flex;
    22. align-items: center;
    23. height: 50px;
    24. justify-content: space-between;
    25. }
    26. .nav input {
    27. height: 23px;
    28. width: 350px;
    29. border-radius: 5px;
    30. box-shadow: 0 1px 0 rgba(255, 255, 255, 0.24),
    31. 0 1px 6px rgba(0, 0, 0, 0.45) inset;
    32. border: none;
    33. padding-left: 10px;
    34. outline: none;
    35. }
    36. .content {
    37. width: 600px;
    38. margin: 0 auto;
    39. }
    40. .content-nav {
    41. display: flex;
    42. justify-content: space-between;
    43. font-size: 25px;
    44. font-weight: bold;
    45. margin: 20px 0;
    46. align-items: center;
    47. }
    48. .content-nav span {
    49. font-size: 14px;
    50. width: 20px;
    51. height: 20px;
    52. background: rgb(238, 236, 236);
    53. border-radius: 10px;
    54. text-align: center;
    55. line-height: 20px;
    56. }
    57. .iconfont {
    58. color: #cccccc;
    59. cursor: pointer;
    60. }
    61. .list {
    62. background: #fff;
    63. display: flex;
    64. justify-content: space-around;
    65. height: 32px;
    66. align-items: center;
    67. border-radius: 5px;
    68. border-left: 5px solid #629a9c;
    69. margin-bottom: 10px;
    70. }
    71. .content input {
    72. width: 22px;
    73. height: 22px;
    74. cursor: pointer;
    75. }
    76. .text {
    77. width: 505px;
    78. overflow: hidden;
    79. white-space: nowrap;
    80. text-overflow: ellipsis;
    81. }
    82. .foot {
    83. text-align: center;
    84. color: #666;
    85. }
    86. .list-complete {
    87. opacity: 0.3;
    88. border-left: 5px solid #666;
    89. }