【发布时间】:2019-09-29 09:11:48
【问题描述】:
由于 Dom 元素,我在使用 react-konva 时遇到了问题。当我尝试添加一个函数来根据 dom 的大小调整 konva 的屏幕大小时。添加图层后出现此错误。
const checkSize = contentRect => {
const { width, height } = contentRect;
stage.attrs({
width,
height
});
stage.batchDraw();
};
export default class Review extends React.Component {
constructor(props) {
super(props);
this.state = { stage: {} };
}
componentDidMount() {
const { values, colorValue } = this.props;
imageValue = values;
colourValue = colorValue;
this.state.stage = new Konva.Stage({
container: "container",
width: 0,
height: 0
});
window.addEventListener("resize", checkSize);
}
它在那个阶段抛出一个错误
layer = new Konva.Layer();
stage.add(layer);
错误信息: TypeError: 阶段未定义
【问题讨论】:
标签: javascript reactjs konvajs react-konva