comp-swiper.component.ts 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import { Component, AfterViewInit, Input } from '@angular/core';
  2. // import Swiper JS
  3. import Swiper from 'swiper';
  4. interface SwiperSlide{
  5. title?:string
  6. img?:string
  7. innerHTML?:string
  8. }
  9. @Component({
  10. selector: 'comp-swiper',
  11. templateUrl: './comp-swiper.component.html',
  12. styleUrls: ['./comp-swiper.component.scss'],
  13. standalone: true,
  14. })
  15. export class CompSwiperComponent implements AfterViewInit {
  16. @Input() list:SwiperSlide[] = []
  17. /**
  18. * 轮播图参数
  19. * @see https://swiperjs.com/swiper-api
  20. */
  21. @Input() options:any
  22. @Input() height:string = "150px";
  23. @Input() width:string = "100%";
  24. constructor() { }
  25. ngAfterViewInit() {
  26. let defaultOptions:any = {
  27. loop:true,
  28. // // If we need pagination
  29. // pagination: {
  30. // el: '.swiper-pagination',
  31. // },
  32. // // Navigation arrows
  33. // navigation: {
  34. // nextEl: '.swiper-button-next',
  35. // prevEl: '.swiper-button-prev',
  36. // },
  37. }
  38. if(this.options){
  39. Object.keys(this.options).forEach(key=>[
  40. defaultOptions[key] = this.options[key]
  41. ])
  42. }
  43. const swiper = new Swiper(".swiper",defaultOptions);
  44. }
  45. }