物业 'SVGResize' | “在onResize”类型上不存在“SVGProps “

问题描述 投票:1回答:1

反应+ SVG。

我需要处理svg元调整大小的事件。我看到它有SVGResizeonresize事件。我尝试用他们每个人,但我得到了每种情况的编译错误:

const msg1 = (e: any) => console.log(`Message 1: SVG resized.`);
const msg2 = (e: any) => console.log(`Message 2: SVG resized.`);

现在,我尝试使用我的功能:

return (<svg id={this.paperId} height={height} version="1.1" 
width={width} xmlns="http://www.w3.org/2000/svg" className="paper" 
SVGResize={msg1}> </svg>);

编译错误:

住宅“SVGResize”上不存在型“SVGProps”。

return (<svg id={this.paperId} height={height} version="1.1" 
width={width} xmlns="http://www.w3.org/2000/svg" className="paper" 
onresize={msg2}> </svg>);

编译错误:

住宅“在onResize”上键入“SVGProps”不存在。

我怎样才能解决这个问题?

javascript reactjs typescript svg
1个回答
0
投票

该事件的onResize是全球性的事件处理程序的属性。这是一样的window.onresize和做的元素级别罢了。

https://developer.mozilla.org/en-US/docs/Web/API/GlobalEventHandlers/onresize

如果你想重绘根据窗口大小svgs你应该听的window.onresize事件重绘基于这一点。

© www.soinside.com 2019 - 2024. All rights reserved.