vue使用lodash进行函数节流处理

65 阅读1分钟
1.npm i lodash 安装lodash插件
2.在mian.js中进行配置
import { _ } from "lodash";

Vue.prototype._ = _;
3. 使用节流函数
export default {
data() {
    return {
    };
  },
  methods: {
	confirm: _.throttle(function () {
      //this.dialogVisible = false;
      this.$post("", {
      }).then((res) => {
        if (res.code == 20000) {
          this.$message.success(res.message);
          //this.getInfo();
        } else {
          this.$message.error(res.message);
        }
      });
    }, 5000,{
      leading:true, //指定调用在节流开始前
      trailing:false //指定调用在节流结束后,
    }),
}
}