yf-carsousel.vue 962 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <template>
  2. <swiper
  3. :interval="3000"
  4. :duration="1000"
  5. :indicator-dots="true"
  6. :current="current" @change="swiperTab"
  7. :autoplay="true"
  8. :circular="true"
  9. class="swiper"
  10. >
  11. <swiper-item v-for="(item,index) in dataList" :key="index">
  12. <image :src="item.url" class="swiper-img" mode="aspectFill"></image>
  13. </swiper-item>
  14. </swiper>
  15. </template>
  16. <script>
  17. export default {
  18. name: "yf-carsousel",
  19. props:{
  20. imgList: {
  21. type: Array,
  22. default() {
  23. return []
  24. }
  25. }
  26. },
  27. data() {
  28. return {
  29. current: 0,
  30. dataList: []
  31. }
  32. },
  33. watch: {
  34. imgList: {
  35. handler(val) {
  36. console.log('watch....', val)
  37. this.dataList = val
  38. },
  39. deep: true
  40. }
  41. },
  42. mounted() {
  43. this.dataList = this.imgList
  44. },
  45. methods: {
  46. swiperTab(e) {
  47. var that = this;
  48. this.current = Number(e.target.current);
  49. }
  50. }
  51. }
  52. </script>
  53. <style>
  54. .swiper, .swiper-img {
  55. width: 100vw;
  56. height: 45vw;
  57. }
  58. </style>