v-throttle 实现 import type { ThrottleSettings } from 'lodash-es' import type { AnyFC } from '@/types/modules/utils' export interface ThrottleBindingOptions { func: AnyFC trigger?: string wait?: number options?: ThrottleSettings } import { throttle } from 'lodash-es' import { on, off }...
在lodash的throttle方法中,可以直接使用function,而且额外的好处是无需重新指向this,在函数内部中,已经做了apply,所以这里的this指向的就是vue实例,这样对已有函数的改造也是十分的方便,外面包一层_.throttle就可以了! 注意 不要在throttle或者debounce中使用箭头函数,会导致this指向不正确,lodash中已通过apply为function继...