mport React from 'react'
import './style.css'
/**
* 功能:默认设置界面
*/
function getComponentCookie() {
return import('../../utils/cookie').then(Cookie=> {
//var timer_flag = Cookie.getCookie('timer');
//console.log('timer_flag');
//console.log(timer_flag)
}).catch(error => 'An error occurred while loading the component');
}
class RightList extends React.Component {
constructor(props) {
super(props);
this.state = {
show : true
};
}
handleClick() {
var that = this;
// 点击按钮改变样式
console.log('点击帮助列表');
console.log(this.state.show);
if(this.state.show)
{
document.getElementById('parent').style.display = 'block';
}
else
{
document.getElementById('parent').style.display = 'none';
}
this.setState({show: !this.state.show});
}
//组件的props发生改变,在组件接收到一个新的prop时被执行。这个方法在初始化render时不会被调用。
componentWillReceiveProps(nextProps) {
if(nextProps) {
this.setState(
{
text:nextProps.text
}
);
}
}
componentDidMount() { // 初始化render之后只执行一次
//console.log('定时器结尾');
document.getElementById('parent').style['fontSize'] = '85px';
}
render() {
return (
<div id='parent' onClick={this.handleClick}>
开启轮播=={this.props.text}
</div>
)
}
}
export default RightList;
import React from 'react'
import './style.css'
/**
* 功能:默认设置界面
*/
class RightList extends React.Component {
constructor(props) {
super(props);
this.state = {
show : true
};
}
handleClick() {
this.setState({show:!this.state.show});
event.stopPropagation()
event.preventDefault()
// 点击按钮改变样式
//console.log('点击帮助列表');
}
componentDidMount() { // 初始化render之后只执行一次
//console.log('定时器结尾');
//document.getElementById('parent').style['fontSize'] = '85px';
}
render() {
var show= this.state.show?"block":"none";
var style = {
display:show,
fontSize: 85
}
return (
<div id='parent' onClick={this.handleClick} style={style}>
开启轮播=={this.props.text}
</div>
)
}
}
export default RightList;

隐藏后就无法显示了
import React from 'react'
import './style.css'
/**
* 功能:默认设置界面
*/
class RightList extends React.Component {
constructor(props) {
super(props);
this.state = {
show : true
};
}
handleClick() {
this.setState({show:!this.state.show});
event.stopPropagation()
event.preventDefault()
// 点击按钮改变样式
//console.log('点击帮助列表');
if(this.state.show)
{
document.getElementById('parent').style.display = 'block';
}
else
{
document.getElementById('parent').style.display = 'none';
}
}
componentDidMount() { // 初始化render之后只执行一次
//console.log('定时器结尾');
document.getElementById('parent').style['fontSize'] = '85px';
}
render() {
return (
<div id='parent' onClick={this.handleClick.bind(this)} >
开启轮播=={this.props.text}
</div>
)
}
}
export default RightList;
不要操作dom不要操作dom不要操作dom!!!
and
为什么隐藏之后不显示???
兄弟,你都
display: none
了,这dom都没了,你点都点不到它,你还怎么触发它上面的click事件啊两种方案
1.外面包一层有宽高的div,点击事件放在这个div上面
2.改变透明度