element系列 - pagination 改造

237 阅读1分钟

系列

element系列 - input 改造

element系列 - select 改造

element系列 - form 改造

element系列 - tree 改造

element系列 - pagination 改造

需求

  • 引入lodash,给 pagination 加防抖

github项目地址

代码

import Vue from "vue";
import { debounce } from "lodash";
import { Pagination } from "element-ui";
const elPaginationHack = {
  install: (Vue) => {
    //ElementUI分页回调添加防抖
    const onPagerClick = Pagination.components.Pager.methods.onPagerClick;
    Object.assign(Pagination.components.Pager.methods, {
      onPagerClick: debounce(
        function (...args) {
          //调用原方法
          onPagerClick.apply(this, args);
        },
        300,
        {
          leading: true,
          trailing: false,
        }
      ),
    });

    Vue.use(Pagination);
  },
};
Vue.use(elPaginationHack);