简体   繁体   English

属性“ SVGResize” | &#39;onresize&#39;在&#39;SVGProps&#39;类型上不存在 <SVGSVGElement> &#39;

[英]Property 'SVGResize' | 'onresize' does not exist on type 'SVGProps<SVGSVGElement>'

React + SVG. React + SVG。

I need to handle the event of svg element resizing. 我需要处理svg元素大小调整的事件。 I see it has the SVGResize and onresize events. 我看到它具有SVGResizeonresize事件。 I try to use each of them but I get the compilation error for each case: 我尝试使用它们中的每一个,但每种情况下都会出现编译错误:

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

Now I try to use my functions: 现在,我尝试使用我的函数:

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

Compilation error: 编译错误:

Property 'SVGResize' does not exist on type 'SVGProps'. 属性“ 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>);

Compilation error: 编译错误:

Property 'onresize' does not exist on type 'SVGProps'. 属性“ onresize”在类型“ SVGProps”上不存在。

How can I fix it? 我该如何解决?

The onresize event is a property of global event handlers. onresize事件是全局事件处理程序的属性。 It is the same as window.onresize and does nothing on the element level. 它与window.onresize相同,并且在元素级别不执行任何操作。

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

If you want to redraw the svgs based on the window size you should listen for the window.onresize event and redraw based on that. 如果要根据窗口大小重新绘制svg,则应侦听window.onresize事件并根据该事件重新绘制。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM