javascript - this.transformer.anchorSize 不是函数
问题描述
我试图在 React Konva 中对 Transformer 组件进行一些更改,并且每当我尝试更改锚点大小时都会遇到此错误。我遵循文档中所述的语法 - https://konvajs.github.io/api/Konva.Transformer.html#validateAnchors__anchor
问题在于anchorSize。请帮我。这是代码 -
class TransformerComponent extends React.Component {
componentDidMount () {
this.checkNode ();
}
componentDidUpdate () {
this.checkNode ();
}
checkNode() {
const stage = this.transformer.getStage();
const { selectedShapeName } = this.props;
const selectedNode = stage.findOne ('.' + selectedShapeName);
this.transformer.rotateEnabled (false);
this.transformer.anchorSize (5);
if (selectedNode === this.transformer.node()) {
return;
}
if (selectedNode) {
this.transformer.attachTo (selectedNode);
}
else {
this.transformer.detach();
}
this.transformer.getLayer().batchDraw();
}
render() {
return (
<Transformer
ref = {node => {
this.transformer = node;
}}
/>
);
}
}
解决方案
您需要将其绑定 如下checkNode()
:
class TransformerComponent extends React.Component {
constructor(props) {
super(props)
this.checkNode = this.checkNode.bind(this)
}
...