我一直在使用composition API在vue 3的watch函数中触发debounce函数时遇到麻烦。我让它在选项API中工作。watch函数正在工作(只是不是watcher内部的debounce函数)。
setup() {
const handleDebounce = (fn, delay) => {
console.log('test') // this works
var timeoutID = null
return function () {
console.log('test') // this does not work
clearTimeout(timeoutID)
var args = arguments
var that = this
timeoutID = setTimeout(function () {
fn.apply(that, args)
}, delay)
}
}
watch(
() => watched.value,
input => {
//doesn't work
handleDebounce(function (t) {
console.log(t)
}, 3000)
}
)
}
字符串
1条答案
按热度按时间k0pti3hp1#
或者这样写手表:
字符串
或者在手表外部创建一个去抖动函数,然后在手表内部调用它。
型