todoList
案例相关知识点className、style
的写法state
中?
state
中state
中(官方称此操作为:状态提升)props
传递props
传递,要求是父提前给子传递一个函数defaultChecked
和checked
区别,类似还有defaultValue
和value
案例:
文件目录结构:
App.js:
app.module.css:
Hearder
index.jsx
index.css
.search {
width: calc(100% - 20px);
padding: 10px;
}
List
index.jsx
idnex.css
ul {
list-style: none;
margin: 0;
padding: 0;
}
Item
index.jsx
index.module.css
.li-content{
display: flex;
justify-content: space-between;
padding: 2px 5px;
}
.del {
border: none;
background: none;
font-size: 18px;
font-weight: bold;
color: red;
}
Footer:
index.jsx
index.module.css
.footer {
display: flex;
justify-content: space-between;
align-items: center;
height: 50px;
padding: 10px 20px;
border-top: 1px solid #ccc;
}
.count{
margin-left: 20px;
}
button {
width: 150px;
height: 40px;
background-color: rgb(255, 0, 72);
border-radius: 20px;
color: #fff;
cursor: pointer;
}
8.运行效果
代理到服务器的5000端口,前端端口是3000,请求时候http://localhost:3000/students 所有3000端口下没有的资源都会转发到http://localhost:5000,如果有则不转发
配置多个代理
pubSub
)yarn add pubsub-js
**List/index.jsx
// 一挂载好就订阅消息
import PubSub from 'pubsub-js'
componentDidMount(){
this.pub = PubSub.subscribe('defClick', (_, data) => {
this.setState(data)
})
}
// 取消订阅
componentWillUnmount(){
PubSub.unsubscribe(this.pub)
}
Hearder/index.jsx
import PubSub from 'pubsub-js'
PubSub.publish('defClick', {val})