Skip to content

Commit 573b543

Browse files
committed
feat: todoList总结
1 parent c6bccae commit 573b543

File tree

4 files changed

+108
-0
lines changed

4 files changed

+108
-0
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@
250250
- [React 组件 API](./react/API.md)
251251
- [React 组件生命周期](./react/组件生命周期.md)
252252
- [React Refs](./react/Refs.md)
253+
- [todoList总结](./react/todoList.md)
253254

254255
### 阶段二
255256

@@ -271,6 +272,8 @@
271272
- [Update和UpdateQueue](./react/Update和UpdateQueue.md)
272273
- [react脚手架](./react/react脚手架.md)
273274
- [消息订阅与发布](./react/消息订阅与发布.md)
275+
- [fetch](./react/fetch.md)
276+
274277

275278
## 常见问题及解答
276279

react/fetch.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
fetch的出现就是为了解决XHR的问题:
2+
3+
使用XHR发送一个json请求一般是这样:
4+
5+
```js
6+
var xhr = new XMLHttpRequest();
7+
xhr.open('GET', url);
8+
xhr.responseType = 'json';
9+
10+
xhr.onload = function() {
11+
console.log(xhr.response);
12+
};
13+
14+
xhr.onerror = function() {
15+
console.log('eerror')
16+
}
17+
18+
xhr.send();
19+
```
20+
21+
fetch:
22+
23+
```js
24+
fetch('').then(
25+
response => {
26+
console.log('联系服务器成功了');
27+
return response.json()
28+
},
29+
error => {console.log('联系服务器失败了', error)}
30+
).then(
31+
response => {console.log('获取数据成功了', response)},
32+
error => {console.log('获取数据失败了', error)}
33+
)
34+
```
35+
36+
```js
37+
try {
38+
const response = await fetch('')
39+
const data = await response.json()
40+
console.log(data)
41+
} catch (error) {
42+
console.log('请求出错', error)
43+
}
44+
```
45+

react/todoList.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
1. 拆分组件,实现静态组件,注意:className,style 的写法
2+
2. 动态初始化列表,如何确定将数据放在哪个组件的state中?
3+
4+
某个组件使用:放在其自身的state中
5+
6+
某些组件使用:放在他们共同的父组件state中
7+
8+
3. 关于父子之间通信
9+
10+
【父组件】给【子组件】传递数据:通过props传递
11+
12+
【子组件】给【父组件】传递数据:通过props传递,要求父提前给子传递一个函数
13+
14+
4. 注意defaultChecked 和 checked 的区别,类似的还有: defaultValue 和 value
15+
16+
5. 状态在哪里,操作状态的方法就在哪里
17+
18+
设计状态时要考虑全面,例如带有网络请求的组件,要考虑请求失败怎么办。
19+
20+
ES6小知识点: 解构赋值+重命名
21+
22+
```js
23+
let obj = {a: {b:1} }
24+
const {a} = obj; // 传统解构赋值
25+
const {a:{b}} = obj; // 连续解构赋值
26+
const {a:{b:value}} = obj; // 连续解构赋值+重命名
27+
```
28+
29+
消息订阅与发布机制
30+
31+
1. 先订阅,再发布
32+
2. 适用于任意组件通信
33+
3. 要在组件的componentWillUnmount中取消订阅
34+
35+
fetch发送请求
36+
37+
```js
38+
try {
39+
40+
}catch(error) {
41+
42+
}
43+
```

react/消息订阅与发布.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,20 @@
1010
2. PubSub.subscribe('delete', function(data){}); // 订阅
1111
3. PubSub.publish('delete', data) // 发布消息
1212

13+
```js
14+
var mySubscriber = function(msg, data) {
15+
console.log(msg, data);
16+
};
17+
18+
var token = PubSub.subscribe('MY TOPIC', mySubscriber);
19+
20+
PubSub.unsubscribe(token);
21+
```
22+
23+
```js
24+
var mySubscriber = function (msg, data) {
25+
console.log()
26+
}
27+
28+
PubSub.publish('消息名', 'hello world')
29+
```

0 commit comments

Comments
 (0)