index.mjs 988 B

12345678910111213141516171819202122232425262728293031
  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. install(app, options = {}) {
  7. const LazyClass = Lazy();
  8. const lazy = new LazyClass(options);
  9. const lazyContainer = new LazyContainer({ lazy });
  10. app.config.globalProperties.$Lazyload = lazy;
  11. if (options.lazyComponent) {
  12. app.component("LazyComponent", LazyComponent(lazy));
  13. }
  14. if (options.lazyImage) {
  15. app.component("LazyImage", LazyImage(lazy));
  16. }
  17. app.directive("lazy", {
  18. beforeMount: lazy.add.bind(lazy),
  19. updated: lazy.update.bind(lazy),
  20. unmounted: lazy.remove.bind(lazy)
  21. });
  22. app.directive("lazy-container", {
  23. beforeMount: lazyContainer.bind.bind(lazyContainer),
  24. updated: lazyContainer.update.bind(lazyContainer),
  25. unmounted: lazyContainer.unbind.bind(lazyContainer)
  26. });
  27. }
  28. };
  29. export {
  30. Lazyload
  31. };