vue中lodasdh结合element ui在查询中使用节流

节流:

throttle 的中心思想在于:在某段时间内,不管你触发了多少次回调,我都只认第一次,并在计时结束时给予响应。

看代码:

# npm
npm install lodash

#yarn
yarn add lodash
  <el-button @click="throttledMethod">点击了</el-button>

   // 用了节流函数
   // 注意:使用lodash必须通过这种方式,throttle的箭头函数,里面的this反而为undefined
   //必须通过function(event),里面的this才是指向vue
     throttledMethod:  _.throttle(function(event) {
    
    
     this.changeName();
    }, 4000),
 
       changeName(){
    
    
        console.log("4秒后触发");
       }

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/qq_42931285/article/details/124702021