1- import React from ' react' ;
2- import Vcode from ' ../../dist/index.js' ;
3- import ReactDom from ' react-dom' ;
4- import ImgTest1 from ' ../assets/test1.png' ;
5- import ImgTest2 from ' ../assets/test2.png' ;
1+ import React from " react" ;
2+ import Vcode from " ../../dist/index.js" ;
3+ import ReactDom from " react-dom" ;
4+ import ImgTest1 from " ../assets/test1.png" ;
5+ import ImgTest2 from " ../assets/test2.png" ;
66class Test extends React . Component {
77 constructor ( props ) {
88 super ( props ) ;
99 this . state = {
1010 img : 1 ,
11- input2 : '' , // 第2个input的值
12- vcode2 : '-1' , // 第2个vcode的值
13- code : '' ,
11+ input2 : "" , // 第2个input的值
12+ vcode2 : "-1" , // 第2个vcode的值
13+ code : "" ,
1414 width : 200 ,
1515 } ;
1616 }
@@ -22,7 +22,7 @@ class Test extends React.Component {
2222 }
2323
2424 onVcode2Change ( v ) {
25- console . log ( ' 触发回调onChange' , v ) ;
25+ console . log ( " 触发回调onChange" , v ) ;
2626 if ( v ) {
2727 this . setState ( {
2828 vcode2 : v ,
@@ -35,18 +35,18 @@ class Test extends React.Component {
3535 this . setState ( {
3636 img : imgindex ,
3737 code : imgindex === 1 ? ImgTest1 : ImgTest2 ,
38- vcode2 : '1234' ,
38+ vcode2 : imgindex === 1 ? "wow1" : "helloworld" ,
3939 } ) ;
4040 }
4141 onChangeStr ( ) {
42- const a = [ 'a' , 'b' , 'c' , 'd' ] ;
42+ const a = [ "a" , "b" , "c" , "d" ] ;
4343 const d = [ ] ;
4444 for ( let i = 0 ; i < 5 ; i ++ ) {
4545 d . push ( a [ Math . round ( Math . random ( ) * 3 ) ] ) ;
4646 }
47- console . log ( ' code:' , d ) ;
47+ console . log ( " code:" , d ) ;
4848 this . setState ( {
49- code : d . join ( '' ) ,
49+ code : d . join ( "" ) ,
5050 } ) ;
5151 }
5252
@@ -55,7 +55,7 @@ class Test extends React.Component {
5555 }
5656 onChangeWidth ( ) {
5757 const l = Math . round ( Math . random ( ) * 800 + 400 ) ;
58- console . log ( ' 改变width:' , l ) ;
58+ console . log ( " 改变width:" , l ) ;
5959 this . setState ( {
6060 width : l ,
6161 } ) ;
@@ -64,9 +64,21 @@ class Test extends React.Component {
6464 return (
6565 < div >
6666 < div >
67- < input type = "text" placeholder = "请输入正确的验证码" value = { this . state . input2 } onChange = { e => this . onInput2Change ( e ) } maxLength = { 20 } />
68- < Vcode onChange = { v => this . onVcode2Change ( v ) } value = { this . state . code } width = { this . state . width } />
69- < span > { this . state . input2 === this . state . vcode2 ? '输入正确' : '输入错误' } </ span >
67+ < input
68+ type = "text"
69+ placeholder = "请输入正确的验证码"
70+ value = { this . state . input2 }
71+ onChange = { ( e ) => this . onInput2Change ( e ) }
72+ maxLength = { 20 }
73+ />
74+ < Vcode
75+ onChange = { ( v ) => this . onVcode2Change ( v ) }
76+ value = { this . state . code }
77+ width = { this . state . width }
78+ />
79+ < span >
80+ { this . state . input2 === this . state . vcode2 ? "输入正确" : "输入错误" }
81+ </ span >
7082 </ div >
7183 < hr />
7284 < button onClick = { ( ) => this . onChangeImg ( ) } > 更换图片</ button >
@@ -77,4 +89,4 @@ class Test extends React.Component {
7789 }
7890}
7991
80- ReactDom . render ( < Test /> , document . getElementById ( ' root' ) ) ;
92+ ReactDom . render ( < Test /> , document . getElementById ( " root" ) ) ;
0 commit comments