我有一个包含徽标的登录页面。我试图让这个标志触发状态值的变化。这样做的目的是在点击时将着陆页更改为主页。我已经设置好了,以便在确定的时间内清除目标网页,但我希望在点击时完成此操作。这是我splash.js
文件,其中包含上点击功能以及标志和着陆页:如何将点击功能链接到React应用中的另一个组件?
import React, { Component } from 'react';
import Woods from './woods.jpeg';
import Logo1 from './whitestar.png';
export default class Splash extends Component {
constructor() {
super();
this.toggleShowHome = this.toggleShowHome.bind(this);
}
toggleShowHome(property){
this.setState((prevState)=>({[property]:!prevState[property]}))
}
render() {
return(
<div id='Splashwrapper'>
<img src={Woods}></img>
<img id='logoc' src={Logo1} onClick={()=>this.toggleShowHome('showSquareOne')}></img>
</div>
);
}
}
我想上点击功能改变我App.js
文件的splash
为false值:
import React, { Component } from 'react';
import Splash from './splash';
import Menu from 'components/Global/Menu';
export default class About extends Component {
constructor(){
super();
this.state = {
splash: true
}
}
componentDidMount() {
setTimeout (() => {
this.setState({splash: false});
}, 10000);
}
render() {
if (this.state.splash) {
return <Splash />
}
const { children } = this.props; // eslint-disable-line
return (
<div className='About'>
<Menu />
{ children }
</div>
);
}
}
如何将点击功能链接到App.js
文件并更改splash
的值?
灿没有得到这个工作https://pastebin.com/btYqGCQE .. – feners
对不起。它应该是'onClick = {this.props.onLogoClicked}'。我已经适当地编辑了我的答案。 –
由于某些原因,我无法让它正常工作.'logoClicked(foo)''应该改变点击徽标时的状态是不是正确? – feners