当在img上使用'onerror'事件时,我会不断收到警告消息。关于如何解决这个问题有任何想法吗?
错误:不应该为非交互式元素分配鼠标或键盘事件侦听器
jsx:
const handlerErrorNoImage = (event) => {
event.target.src = blankProfile
}
<img src="./myimage" onError={handlerErrorNoImage} alt="" />
我没有研究为什么onError
被解释为鼠标或键盘事件。但是,以下至少消除了警告:
// eslint-disable
<img src="./myimage" onError={handlerErrorNoImage} alt="" />
// eslint-enable