-
Notifications
You must be signed in to change notification settings - Fork 395
Open
Description
防抖函数debounce在setTimeout中通过apply执行的函数(debounce第一个参数)中的this(apply第一个参数)测试为undefined,感觉应该在debounce中传入一个'this'(项目中为this.$refs.scroll)
// 防抖函数 export function debounce(func, that = null, delay = 500) { // 回调函数,和回调函数要执行须等待的时间ms let timer = null // this => Vue组件 return function (...args) { // this => undefined if (timer) { clearTimeout(timer) } timer = setTimeout(() => { // 测试证明此处使用this => undefined func.apply(that, args) //func() }, delay) } }
Metadata
Metadata
Assignees
Labels
No labels