Skip to content

Commit 9a8ea6c

Browse files
committed
edit md
1 parent c5493bb commit 9a8ea6c

3 files changed

Lines changed: 19 additions & 12 deletions

File tree

‎react/component/src/event/README.md‎

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
## 事件和 ref
1+
# 事件和 ref
2+
23
事件可以直接写到 DOM 节点,然后通过 ref 来获取 DOM 节点
34
```javascript
45
import React from 'react';
@@ -20,7 +21,10 @@ class Component1 extends React.Component{
2021

2122
ReactDOM.render(<Component1/>, document.getElementById('div1'));
2223
```
23-
[效果预览](https://wscats.github.io/react-tutorial/react/component/src/event/event.html)
24+
25+
### 效果预览
26+
27+
- [ref的使用](https://wscats.github.io/react-tutorial/react/component/src/event/event.html)
2428

2529
## 事件对象 —— event
2630
React 在事件方法调用上默认会传一个形参`events`,该对象是一个合成事件,所以不需要担心浏览器兼容的问题。
@@ -43,9 +47,11 @@ ReactDOM.render(
4347
)
4448
```
4549

46-
## 事件 —— this 指针
50+
# 事件 —— this 指针
51+
4752
在所有的事件当中,首先都要弄明白 `this` 指向哪里。而 React 事件中(如上面的案例)默认的 `this` 都是 `undefined`,为了 this 指针能正确指回组件对象本身,通常可以用下面几种方法。
48-
### 事件定义使用箭头函数
53+
54+
## 事件定义使用箭头函数
4955
```javascript
5056
class Component1 extends React.Component{
5157
submit = (e) => {
@@ -57,7 +63,7 @@ class Component1 extends React.Component{
5763
}
5864
}
5965
```
60-
### 事件调用时使用用箭头函数
66+
## 事件调用时使用用箭头函数
6167
```javascript
6268
class Component1 extends React.Component{
6369
submit(e){
@@ -69,7 +75,7 @@ class Component1 extends React.Component{
6975
}
7076
}
7177
```
72-
### 构造函数中使用 bind
78+
## 构造函数中使用 bind
7379
```javascript
7480
class Component1 extends React.Component{
7581
constructor(props){
@@ -85,7 +91,7 @@ class Component1 extends React.Component{
8591
}
8692
}
8793
```
88-
### 事件调用时用 bind
94+
## 事件调用时用 bind
8995
```javascript
9096
class Component1 extends React.Component{
9197
submit(e){
@@ -98,8 +104,9 @@ class Component1 extends React.Component{
98104
}
99105
```
100106

101-
## 事件传参数
102-
### 事件调用时使用用箭头函数
107+
# 事件传参数
108+
109+
## 事件调用时使用用箭头函数
103110
```javascript
104111
class Component1 extends React.Component{
105112
submit(e, n){
@@ -111,7 +118,7 @@ class Component1 extends React.Component{
111118
}
112119
}
113120
```
114-
### 事件调用时用 bind
121+
## 事件调用时用 bind
115122
```javascript
116123
submit(n, e){
117124
console.log(n)

‎react/component/src/render/README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,4 +214,4 @@ ReactDOM.render(
214214

215215
### 效果预览
216216

217-
-[组件子节点](https://wscats.github.io/react-tutorial/react/component/src/props/props.html)
217+
- [组件子节点](https://wscats.github.io/react-tutorial/react/component/src/props/props.html)

‎react/jsx/README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ let methods = {
279279

280280
## this的指向
281281

282-
`onClick={this.test}`这里是不能用加括号的这种方式来传参`onClick={this.test(params)}`,并且这样写之后`this.test`里面的this会是`undefined`,所以在react,函数带参数是要配合`bind`方法,通过`bind`获取`this`和参数
282+
`onClick={this.test}`这里是不能用加括号的这种方式来传参`onClick={this.test(params)}`,并且这样写之后`this.test`里面的this会是`undefined`,所以在react,函数带参数是要配合`bind`方法,通过`bind`获取`this`和参数,深入了解请看[事件 —— this 指针](https://github.com/wscats/react-tutorial/tree/master/react/component/src/event#%E4%BA%8B%E4%BB%B6--this-%E6%8C%87%E9%92%88)
283283
```html
284284
<button @click="test()">ok</button>
285285
<button onClick={this.test}>ok</button>

0 commit comments

Comments
 (0)