react 组件封装
import React from 'react';
// import ReactDOM from 'react-dom';
import './App.css';
class LoginCtrol extends React.Component {
constructor(props) {
super(props);
this.state = {
loginStatus:this.props.ls
};
}
go(flag){
if(flag>0){
alert('登录')
}else{
alert('退出')
}
}
showList(){
let ls=this.state.loginStatus;
if(ls){
return (<button onClick={()=>{this.go(1)}}>登录</button>)
}else{
return (<button onClick={()=>{this.go(-1)}}>退出</button>)
}
}
render() {
let ls=this.state.loginStatus;
let b;
if(ls){
b= <button onClick={()=>{this.go(1)}}>登录</button>
}else{
b=<button onClick={()=>{this.go(-1)}}>退出</button>
}
return (
<div className='login-box'>
{/* {this.showList()} */}
{b}
</div>
);
}
}
export default LoginCtrol;