我的对象有2个属性,当这些属性被命名为左和顶时 { left: rect.left, top: rect.top}
.破坏对象后,我的x和y变量都是NaN。
const { x, y } = this.getCanvasPosition(this.canvasHex.current);
但如果我把该对象的属性重命名为 x 和 y { x: rect.left, y: rect.top}
,我得到了我想要的值。
我想知道这里到底发生了什么。
你需要对属性进行重命名,因为你没有属性。x
和 y
但 left
和 top
.
const { left: x, top: y } = this.getCanvasPosition(this.canvasHex.current);
const { left: x, top: y } = { left: 10, top: 5 };
console.log(x, y);