import React from 'react';
import ReactDom from 'react-dom';
class UserGreeting extends React.Component {
render () {
return (<h1>欢迎回来!</h1>)
}
}
class GuestGreeting extends React.Component {
render () {
return (<h1>请先注册!</h1>)
}
}
class Greeting extends React.Component {
render () {
if (this.props.isLogin == false) {
return (
<GuestGreeting></GuestGreeting>
)
} else {
return (
<UserGreeting></UserGreeting>
)
}
}
}
ReactDom.render(
<div>
<Greeting isLogin={true}></Greeting>
</div>,
document.getElementById('root')
)
React—条件渲染不同的组件
最新推荐文章于 2024-08-03 08:57:17 发布