@@ -3,10 +3,11 @@ import QueueAnim from 'rc-queue-anim';
3
3
import React from 'react' ;
4
4
import ReactDom from 'react-dom' ;
5
5
6
- const App = React . createClass ( {
7
- getInitialState ( ) {
6
+ class App extends React . Component {
7
+ constructor ( props ) {
8
+ super ( props ) ;
8
9
this . index = 100 ;
9
- return {
10
+ this . state = {
10
11
items : [ {
11
12
children : '依次进入1' ,
12
13
key : 1 ,
@@ -27,16 +28,17 @@ const App = React.createClass({
27
28
key : 6 ,
28
29
} ] ,
29
30
} ;
30
- } ,
31
- add ( ) {
31
+ }
32
+
33
+ add = ( ) => {
32
34
const items = this . state . items ;
33
35
items . push ( {
34
36
children : '新节点' ,
35
37
key : this . index ++ ,
36
38
} ) ;
37
39
this . setState ( { items } ) ;
38
- } ,
39
- addTwo ( ) {
40
+ }
41
+ addTwo = ( ) => {
40
42
const items = this . state . items ;
41
43
items . push ( {
42
44
children : '新节点' ,
@@ -47,8 +49,8 @@ const App = React.createClass({
47
49
key : this . index ++ ,
48
50
} ) ;
49
51
this . setState ( { items } ) ;
50
- } ,
51
- remove ( key , e ) {
52
+ }
53
+ remove = ( key , e ) => {
52
54
e . preventDefault ( ) ;
53
55
const items = this . state . items ;
54
56
const target = items . filter ( item => item . key === key ) ;
@@ -60,22 +62,22 @@ const App = React.createClass({
60
62
items . splice ( index , 1 ) ;
61
63
}
62
64
this . setState ( { items } ) ;
63
- } ,
64
- removeAll ( ) {
65
+ }
66
+ removeAll = ( ) => {
65
67
this . setState ( {
66
68
items : [ ] ,
67
69
} ) ;
68
- } ,
69
- removeAndAdd ( ) {
70
+ }
71
+ removeAndAdd = ( ) => {
70
72
const items = this . state . items ;
71
73
items . splice ( items . length - 1 , 1 ) ;
72
74
items . push ( {
73
75
children : `新节点${ Date . now ( ) } ` ,
74
76
key : this . index ++ ,
75
77
} ) ;
76
78
this . setState ( { items } ) ;
77
- } ,
78
- removeAndAddTow ( ) {
79
+ }
80
+ removeAndAddTow = ( ) => {
79
81
const items = this . state . items ;
80
82
items . splice ( items . length - 1 , 1 ) ;
81
83
items . splice ( items . length - 2 , 1 ) ;
@@ -88,12 +90,13 @@ const App = React.createClass({
88
90
key : this . index ++ ,
89
91
} ) ;
90
92
this . setState ( { items } ) ;
91
- } ,
92
- removeTwo ( ) {
93
+ }
94
+ removeTwo = ( ) => {
93
95
const items = this . state . items ;
94
96
items . splice ( 1 , 1 ) ;
95
97
this . setState ( { items } ) ;
96
- } ,
98
+ }
99
+
97
100
render ( ) {
98
101
return (
99
102
< div >
@@ -110,7 +113,7 @@ const App = React.createClass({
110
113
</ QueueAnim >
111
114
</ div >
112
115
) ;
113
- } ,
114
- } ) ;
116
+ }
117
+ }
115
118
116
119
ReactDom . render ( < App /> , document . getElementById ( '__react-content' ) ) ;
0 commit comments