We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
在业务需求中遇到这样的场景,对一个元素同时添加单击和双击事件,发现两个事件会有冲突,导致无法区分单击和双击事件,下面提供两种解决方案:
let count = 0; class App extends Component { handleClick = () => { count++; setTimeout(() => { if (count === 1) { // 单击事件处理 } else if (count === 2) { // 双击事件处理 } count = 0; }, 300); } render() { return ( <div onClick={this.handleClick} /> ) } }
let clickTasks = []; // Array of debounced click events class App extends Component { handleClick = () => { const task = _.debounce(() => { // 单击事件处理 clickTasks = []; }, 300); clickTasks.push(task); task(); } handleDoubleClick = () => { if(clickTasks.length > 0) { _.map(clickTasks, task => task.cancel()); } // 双击事件处理 } render() { return ( <div onClick={this.handleClick} onDoubleClick={this.handleDoubleClick} /> ) } }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
在业务需求中遇到这样的场景,对一个元素同时添加单击和双击事件,发现两个事件会有冲突,导致无法区分单击和双击事件,下面提供两种解决方案:
The text was updated successfully, but these errors were encountered: