正常情况下
防抖
节流
如何实现?
在创建项目时,modules里包含了loadsh
lodash插件:里面封装函数的防抖与节流的业务【闭包+延迟器】
lodash函数库对外暴露:_函数
import _ from lodash 相当于把全部功能引入进来,
但是我们只是需要节流,所以:
import throttle from "lodash/throttle"; //throttle是默认暴露,不用加{}
// 节流:采用ES5写法;throttle回调函数不用箭头函数,可能会出现上下文this的问题
changeIndex: throttle(function (index) {
this.currentIndex = index;
}, 50),