【发布时间】:2018-12-28 16:06:06
【问题描述】:
我想在打开模式时隐藏一个画布。
我正在使用这种模式依赖: https://react-responsive-modal.leopradel.com/#example
父组件包含画布。 子组件可能会使父组件的画布出现 模态已打开。
我尝试在 openModal 函数内部的子组件中这样做。 它没有用。
document.querySelector('#canvas').style.display = "none"
我有这个带有画布线的 App 组件。 这是父组件。
Class App extends Component {
constructor(props) {
super(props)
this.drawCanvas = this.drawCanvas.bind(this)
}
drawCanvas() {
// here is a code to draw the canvas.
// This does not need to be shown
}
componentDidMount() {
this.drawCanvas()
}
render() {
return (
<div>
<canvas id="canvas"></canvas>
<div className="wrapper-all">
<Coluna1 />
<Coluna2 />
</div>
</div>
)
}
}
export default App;
因此,我有一个在其中打开模式的子组件。当模态打开时,这个子组件可能会从父组件中消失。
import React, { Component } from 'react'
import axios from 'axios'
import Modal from 'react-responsive-modal';
class Interiores extends Component {
constructor(props) {
super(props)
open: false
}
}
onOpenModal = () => {
this.setState({ open: true });
//Here is the code that i'm trying to hide
//the canvas
document.querySelector('#canvas').style.display = "none"
};
onCloseModal = () => {
this.setState({ open: false });
};
render() {
const { open } = this.state;
return (
<div>
<Modal open={open} onClose={this.onCloseModal} center>
<button onClick={this.onOpenModal}>Open modal</button>
<p>
modal text here
</p>
</Modal>
</div>
</div>
)
}
}
export default Interiores;
【问题讨论】:
标签: reactjs