Reactjs 当我尝试做反应弹出示例时,它不起作用
我试图做这个react popout的例子,但它似乎不起作用 示例位于底部Reactjs 当我尝试做反应弹出示例时,它不起作用,reactjs,npm,Reactjs,Npm,我试图做这个react popout的例子,但它似乎不起作用 示例位于底部 import React from "react" import Popout from "react-popout" class PopupLogin extends React.Component { constructor(props) { super(props); this.popout = this.popout.bind(this); this.popoutClosed =
import React from "react"
import Popout from "react-popout"
class PopupLogin extends React.Component {
constructor(props) {
super(props);
this.popout = this.popout.bind(this);
this.popoutClosed = this.popoutClosed.bind(this);
this.state = { isPoppedOut: false };
}
popout() {
this.setState({isPoppedOut: true});
}
popoutClosed() {
this.setState({isPoppedOut: false});
}
render() {
if (this.state.isPoppedOut) {
return (
<Popout title='Window title' onClosing={this.popoutClosed}>
<div>Popped out content!</div>
</Popout>
);
} else {
var popout = <span onClick={this.popout} className="buttonGlyphicon glyphicon glyphicon-export"></span>
return (
<div>
<strong>Section {popout}</strong>
<div>Inline content</div>
</div>
);
}
}
}
export default PopupLogin
从“React”导入React
从“react Popout”导入Popout
类PopupLogin扩展了React.Component{
建造师(道具){
超级(道具);
this.popout=this.popout.bind(this);
this.popoutClosed=this.popoutClosed.bind(this);
this.state={isPoppedOut:false};
}
popout(){
this.setState({isPoppedOut:true});
}
popoutClosed(){
this.setState({isPoppedOut:false});
}
render(){
if(this.state.isPoppedOut){
返回(
弹出内容!
);
}否则{
变量弹出=
返回(
节{popout}
内联内容
);
}
}
}
导出默认PopupLogin
这应该是这样的。
但在我的输出中是这样的 文档中的代码似乎缺少文本。在弹出窗口中添加
(弹出窗口)
import React from "react";
import Popout from "react-popout";
class PopupLogin extends React.Component {
constructor(props) {
super(props);
this.popout = this.popout.bind(this);
this.popoutClosed = this.popoutClosed.bind(this);
this.state = { isPoppedOut: false };
}
popout() {
this.setState({ isPoppedOut: true });
}
popoutClosed() {
this.setState({ isPoppedOut: false });
}
render() {
if (this.state.isPoppedOut) {
return (
<Popout title="Window title" onClosing={this.popoutClosed}>
<div>Popped out content!</div>
</Popout>
);
} else {
var popout = (
<span
onClick={this.popout}
className="buttonGlyphicon glyphicon glyphicon-export"
>
<a
style={{
textDecoration: "underline",
color: "blue",
cursor: "pointer"
}}
onClick={this.popout}
>
(pop window out)
</a>
</span>
);
return (
<div>
<strong>Section {popout}</strong>
<div>Inline content</div>
</div>
);
}
}
}
export default PopupLogin;
从“React”导入React;
从“react Popout”导入Popout;
类PopupLogin扩展了React.Component{
建造师(道具){
超级(道具);
this.popout=this.popout.bind(this);
this.popoutClosed=this.popoutClosed.bind(this);
this.state={isPoppedOut:false};
}
popout(){
this.setState({isPoppedOut:true});
}
popoutClosed(){
this.setState({isPoppedOut:false});
}
render(){
if(this.state.isPoppedOut){
返回(
弹出内容!
);
}否则{
变量弹出=(
(弹出窗口)
);
返回(
节{popout}
内联内容
);
}
}
}
导出默认的PopupLogin;
文档中的代码似乎缺少文本。在弹出窗口中添加(弹出窗口)
import React from "react";
import Popout from "react-popout";
class PopupLogin extends React.Component {
constructor(props) {
super(props);
this.popout = this.popout.bind(this);
this.popoutClosed = this.popoutClosed.bind(this);
this.state = { isPoppedOut: false };
}
popout() {
this.setState({ isPoppedOut: true });
}
popoutClosed() {
this.setState({ isPoppedOut: false });
}
render() {
if (this.state.isPoppedOut) {
return (
<Popout title="Window title" onClosing={this.popoutClosed}>
<div>Popped out content!</div>
</Popout>
);
} else {
var popout = (
<span
onClick={this.popout}
className="buttonGlyphicon glyphicon glyphicon-export"
>
<a
style={{
textDecoration: "underline",
color: "blue",
cursor: "pointer"
}}
onClick={this.popout}
>
(pop window out)
</a>
</span>
);
return (
<div>
<strong>Section {popout}</strong>
<div>Inline content</div>
</div>
);
}
}
}
export default PopupLogin;
从“React”导入React;
从“react Popout”导入Popout;
类PopupLogin扩展了React.Component{
建造师(道具){
超级(道具);
this.popout=this.popout.bind(this);
this.popoutClosed=this.popoutClosed.bind(this);
this.state={isPoppedOut:false};
}
popout(){
this.setState({isPoppedOut:true});
}
popoutClosed(){
this.setState({isPoppedOut:false});
}
render(){
if(this.state.isPoppedOut){
返回(
弹出内容!
);
}否则{
变量弹出=(
(弹出窗口)
);
返回(
节{popout}
内联内容
);
}
}
}
导出默认的PopupLogin;
根据他们的文档,您忘记在span中添加文本,因此没有链接,因此没有触发onClick。您可以根据需要设置链接的样式
沙箱:
从“React”导入React;
从“react Popout”导入Popout;
从“react dom”导入react dom;
类PopupLogin扩展了React.Component{
建造师(道具){
超级(道具);
this.popout=this.popout.bind(this);
this.popoutClosed=this.popoutClosed.bind(this);
this.state={isPoppedOut:false};
}
popout(){
this.setState({isPoppedOut:true});
}
popoutClosed(){
this.setState({isPoppedOut:false});
}
render(){
if(this.state.isPoppedOut){
返回(
弹出内容!
);
}否则{
变量弹出=(
打开
);
返回(
节{popout}
内联内容
);
}
}
}
render(,document.getElementById(“根”));
根据他们的文档,您忘记在span中添加文本,因此没有链接,因此没有触发onClick。您可以根据需要设置链接的样式
沙箱:
从“React”导入React;
从“react Popout”导入Popout;
从“react dom”导入react dom;
类PopupLogin扩展了React.Component{
建造师(道具){
超级(道具);
this.popout=this.popout.bind(this);
this.popoutClosed=this.popoutClosed.bind(this);
this.state={isPoppedOut:false};
}
popout(){
this.setState({isPoppedOut:true});
}
popoutClosed(){
this.setState({isPoppedOut:false});
}
render(){
if(this.state.isPoppedOut){
返回(
弹出内容!
);
}否则{
变量弹出=(
打开
);
返回(
节{popout}
内联内容
);
}
}
}
render(,document.getElementById(“根”));
是的,这很有效。这个功能还有其他选择吗?@Gthu替代方案,如中所示?是的,这很有效。此功能还有其他替代方案吗?@Gthu替代方案如中所示?