[英](parameter) e:any error in React typescript
The error says (parameter)e:any
and doesn't compile, I tried changing it to ('submit', e:any)
but that didn't work either, and says错误说
(parameter)e:any
并且无法编译,我尝试将其更改为('submit', e:any)
但这也不起作用,并说
any refers to a type, but it is being used as a value here.
any 指的是一种类型,但在这里它被用作一个值。
How do I simply pass e
into addEventListener
?我如何简单地将
e
传递给addEventListener
?
You should have included a full example of what you're trying, but judging by your description, you're probably setting the type of e
incorrectly.您应该包含您正在尝试的完整示例,但从您的描述来看,您可能错误地设置了
e
的类型。 Try this:尝试这个:
form2.addEventListener('submit', (e: any) => {
// your function here
});
It looks like you're trying看起来你正在尝试
form2.addEventListener('submit', e:any) =>
In that case, please keep in mind that addEventListener
takes two parameters in this case:在这种情况下,请记住
addEventListener
在这种情况下需要两个参数:
submit
),submit
),e => {... }
).e => {... }
)。 So you must set the parameter in said function so it becomes ( (e: any) => {...}
), and that's how we arrive to the aforementioned solution.(e: any) => {...}
),这就是我们到达上述解决方案的方式。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.