安装lodash
npm i --save lodash
引入lodash
import _ from "lodash";
这里用下lodash的debounce作为一个小demo
在constructor中
// this.checkLogin = this.checkLogin.bind(this)
this.checkLogin = _.debounce(this.checkLogin.bind(this),2000)
这样成功调用了 lodash的防抖debounce
当然这样使用 肯定会被你们的组长或者经理给叼死
按需是必不可少的步骤了
引入部分修改:
import _ from "lodash";
//改为下面的引入
import debounce from "lodash/debounce";
在constructor修改
this.checkLogin = _.debounce(this.checkLogin.bind(this),2000)
//改为下面的写法
this.checkLogin = debounce(this.checkLogin.bind(this),2000)
我在这里使用的是class写法
后续看心情更新hook 0.0
2020干巴爹