index.mjs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. import Lazy from "./lazy.mjs";
  2. import LazyComponent from "./lazy-component.mjs";
  3. import LazyContainer from "./lazy-container.mjs";
  4. import LazyImage from "./lazy-image.mjs";
  5. const Lazyload = {
  6. /*
  7. * install function
  8. * @param {App} app
  9. * @param {object} options lazyload options
  10. */
  11. install(app, options = {}) {
  12. const LazyClass = Lazy();
  13. const lazy = new LazyClass(options);
  14. const lazyContainer = new LazyContainer({ lazy });
  15. app.config.globalProperties.$Lazyload = lazy;
  16. if (options.lazyComponent) {
  17. app.component("LazyComponent", LazyComponent(lazy));
  18. }
  19. if (options.lazyImage) {
  20. app.component("LazyImage", LazyImage(lazy));
  21. }
  22. app.directive("lazy", {
  23. beforeMount: lazy.add.bind(lazy),
  24. updated: lazy.update.bind(lazy),
  25. unmounted: lazy.remove.bind(lazy)
  26. });
  27. app.directive("lazy-container", {
  28. beforeMount: lazyContainer.bind.bind(lazyContainer),
  29. updated: lazyContainer.update.bind(lazyContainer),
  30. unmounted: lazyContainer.unbind.bind(lazyContainer)
  31. });
  32. }
  33. };
  34. export {
  35. Lazyload
  36. };