扫码关注官方订阅号
我想在 componentWillMount 下先判断用户是否已经登录,若已经登录显示用户名,没登陆,不显示用户名
如何在componentWillMount 下控制render 函数的渲染?
认证高级PHP讲师
你这应该先定义一个state,假设为user,初始值为nullrender函数中判断user是不是null,如果是null,不显示用户名,如果不是null显示用户名。然后再componentDidMount判断是否登录,登陆了setState({user:用户数据})
微信扫码关注PHP中文网服务号
QQ扫码加入技术交流群
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
PHP学习
技术支持
返回顶部
你这应该先定义一个state,假设为user,初始值为null
render函数中判断user是不是null,如果是null,不显示用户名,如果不是null显示用户名。
然后再componentDidMount判断是否登录,登陆了setState({user:用户数据})