@@ -3,10 +3,11 @@ import QueueAnim from 'rc-queue-anim';
33import React from 'react' ;
44import ReactDom from 'react-dom' ;
55
6- const App = React . createClass ( {
7- getInitialState ( ) {
6+ class App extends React . Component {
7+ constructor ( props ) {
8+ super ( props ) ;
89 this . index = 100 ;
9- return {
10+ this . state = {
1011 items : [ {
1112 children : '依次进入1' ,
1213 key : 1 ,
@@ -27,16 +28,17 @@ const App = React.createClass({
2728 key : 6 ,
2829 } ] ,
2930 } ;
30- } ,
31- add ( ) {
31+ }
32+
33+ add = ( ) => {
3234 const items = this . state . items ;
3335 items . push ( {
3436 children : '新节点' ,
3537 key : this . index ++ ,
3638 } ) ;
3739 this . setState ( { items } ) ;
38- } ,
39- addTwo ( ) {
40+ }
41+ addTwo = ( ) => {
4042 const items = this . state . items ;
4143 items . push ( {
4244 children : '新节点' ,
@@ -47,8 +49,8 @@ const App = React.createClass({
4749 key : this . index ++ ,
4850 } ) ;
4951 this . setState ( { items } ) ;
50- } ,
51- remove ( key , e ) {
52+ }
53+ remove = ( key , e ) => {
5254 e . preventDefault ( ) ;
5355 const items = this . state . items ;
5456 const target = items . filter ( item => item . key === key ) ;
@@ -60,22 +62,22 @@ const App = React.createClass({
6062 items . splice ( index , 1 ) ;
6163 }
6264 this . setState ( { items } ) ;
63- } ,
64- removeAll ( ) {
65+ }
66+ removeAll = ( ) => {
6567 this . setState ( {
6668 items : [ ] ,
6769 } ) ;
68- } ,
69- removeAndAdd ( ) {
70+ }
71+ removeAndAdd = ( ) => {
7072 const items = this . state . items ;
7173 items . splice ( items . length - 1 , 1 ) ;
7274 items . push ( {
7375 children : `新节点${ Date . now ( ) } ` ,
7476 key : this . index ++ ,
7577 } ) ;
7678 this . setState ( { items } ) ;
77- } ,
78- removeAndAddTow ( ) {
79+ }
80+ removeAndAddTow = ( ) => {
7981 const items = this . state . items ;
8082 items . splice ( items . length - 1 , 1 ) ;
8183 items . splice ( items . length - 2 , 1 ) ;
@@ -88,12 +90,13 @@ const App = React.createClass({
8890 key : this . index ++ ,
8991 } ) ;
9092 this . setState ( { items } ) ;
91- } ,
92- removeTwo ( ) {
93+ }
94+ removeTwo = ( ) => {
9395 const items = this . state . items ;
9496 items . splice ( 1 , 1 ) ;
9597 this . setState ( { items } ) ;
96- } ,
98+ }
99+
97100 render ( ) {
98101 return (
99102 < div >
@@ -110,7 +113,7 @@ const App = React.createClass({
110113 </ QueueAnim >
111114 </ div >
112115 ) ;
113- } ,
114- } ) ;
116+ }
117+ }
115118
116119ReactDom . render ( < App /> , document . getElementById ( '__react-content' ) ) ;
0 commit comments