我只是想将 zingtouch 作为事件侦听器添加到我的代码中。我需要向轮子组件添加一个“旋转”事件侦听器。我使用了 componentDidMount() 以便在添加 Wheel 组件后可以获取 html 元素。不仅仅是我无法在这段代码中使用任何简单的 .addEventListener('click') ,因为它给了我同样的错误。
Uncaught TypeError: t.addEventListener is not a function
at Region.js:86:1
这是轮子组件的源代码。
import React from 'react';
import "./Wheel.css";
import ZingTouch from "zingtouch";
class Wheel extends React.Component {
componentDidMount(){
const wheel = document.getElementsByClassName('wheel');
const region = new ZingTouch.Region(wheel);
region.bind(wheel, 'rotate', (e)=>{
console.log('rotating', e);
})
}
render() {
return (
<div className="wheel">
<span className="menu-button">MENU</span>
<button className="select-button">SELECT</button>
<span className="material-symbols-outlined play-pause">play_pause</span>
<span className="material-symbols-outlined fast-forward">
fast_forward
</span>
<span className="material-symbols-outlined fast-rewind">
fast_rewind
</span>
</div>
);
}
}
export default Wheel;