定义了一个skill组件,点击它会打开一个新页面
handleOpen(res){
window.open("details.html");
console.log(datas);//这里可以拿到点击的数据但是怎么传给新开页面的组件呢?
},
render() {
return (
<p className="photo">
<h2 className="lastest-title-photo">最新作品
</h2>
<Row className="skill">
{
this.state.data.map(function(res){
return <Col span="24" key={res.ID} ref="myTextInput">
<p className="slil-card" >
<p className="skill-img" onClick={this.handleOpen.bind(this,res)}>
<img src={res.URL} />
</p>
<p className="skill-content">
<h2 className="skill-title"><span onClick={this.handleOpen.bind(this,res)}>{res.TITLE}</span></h2>
<p className="skill-subtext">{res.SUBTEXT}</p>
</p>
</p>
</Col>
},this)
}
</Row>
</p>
);
我想要在另一个jsx文件中得到我所点击元素的数据该怎么做?
import ReactDOM from 'react-dom';
import React from 'react';
import { render } from 'react-dom';
import Skill from '../component/Skill';
import '../details/all.less';
const App = React.createClass({
getInitialState: function() {
//怎么获取到点击元素的数据?
},
render() {
return (
<p>
<p className="details-head">
<img src=""/>
</p>
</p>
)
}
});
ReactDOM.render(<App />, document.getElementById('web-main1'));
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
两个思路,第一个:
构建父子组件,通过父来当数据中心,子分别从其中取值
使用或自己定义数据中心,如redux,localstorage等
非要用window.open吗?
window.open 会打开一个新页面,我感觉不符合单页的意义
真的要用的话,我感觉只能用windows.open('http://xxx.xxx.xx/some.html?arg1=something&arg2=something);
然后在racet-router中配置,在页面中通的props.params的来获得 arg1,arg2的内容