}
[](()Item/index.jsx
import React, { Component } from ‘react’
import ‘./index.css’
export default class Item extends Component {
render() {
return (
-
-
xxxxx
<button className=“btn btn-danger” style={{display:‘none’}}>删除
)
}
}
[](()Item/index.css
/item/
li {
list-style: none;
height: 36px;
line-height: 36px;
padding: 0 5px;
border-bottom: 1px solid #ddd;
}
li label {
float: left;
cursor: pointer;
}
li label li input {
vertical-align: middle;
margin-right: 6px;
position: relative;
top: -1px;
}
li button {
float: right;
display: none;
margin-top: 3px;
}
li:before {
content: initial;
}
li:last-child {
border-bottom: none;
}
[](()Footer/index.jsx
import React, { Component } from ‘react’
import ‘./index.css’
export default class Footer extends Component {
render() {
return (
已完成0 / 全部2
清除已完成任务
)
}
}
[](()Footer/index.css
/footer/
.todo-footer {
height: 40px;
line-height: 40px;
padding-left: 6px;
margin-top: 5px;
}
.todo-footer label {
display: inline-block;
margin-right: 20px;
cursor: pointer;
}
.todo-footer label input {
position: relative;
top: -1px;
vertical-align: middle;
margin-right: 5px;
}
.todo-footer button {
float: right;
margin-top: 5px;
}
[](()页面效果
[](()四、实现动态组件
===========================================================================
[](()1. 动态初始化页面
状态驱动组件
考虑两个问题 要将状态放在哪? 状态的存储形式是什么?
-
可以将状态放在需要使用状态的 父组件 App中,这样Header和List都可以通过props拿到状态数据
-
状态的存储形式采用对象数组
// 初始化状态
state = {
todos: [
{ id: ‘001’, name: ‘吃饭’, done: true },
{ id: ‘002’, name: ‘睡觉’, done: true },
{ id: ‘003’, name: ‘敲代码’, done: false },
]
}
[](()App.jsx
在App.jsx组件中定义状态state
,通过标签属性传递给子组件List的props
中
export default class App extends Component {
// 初始化状态
state = {
todos: [
{ id: ‘001’, name: ‘吃饭’, done: true },
{ id: ‘002’, name: ‘睡觉’, done: true },
{ id: ‘003’, name: ‘敲代码’, done: false },
]
}
render() {
const {todos} = this.state
return (