【发布时间】:2019-04-02 15:02:40
【问题描述】:
我希望我的动态组件在新选项卡中打开,这样我就可以在初始页面上保留搜索结果。我想打开一个新页面的组件需要从父组件继承多个属性。
我尝试将 window.open() 与我的 onClick 处理程序一起使用。这将打开新选项卡,但不会从所需的父状态继承属性。我尝试使用 localStorage.setItem(),但这太老套了,只能根据用户的浏览器设置工作。
这是创建新页面的 onclick 方法。我希望能够让它从这里打开一个新标签。
handleContract = (id) => {
API.openRow(id)
.then(res => {
const pdfs = res.data;
this.setState({pdfs});
this.props.history.push({
pathname: '/pdf',
state: { labels:this.state.labels,
pdfs:this.state.pdfs,
titles:this.state.titles }
})
})
.catch(err => console.log(err));
API.titles(id)
.then(res => {
const titles = res.data;
this.setState({titles});
})
}
作为次要选项。是否可以在我的 onClick 方法上弹出一个模式并以这种方式显示组件?
【问题讨论】:
标签: reactjs parameters onclick window.open