zhuge-swiper.vue 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <template>
  2. <swiper class="swiper" :autoplay="swiperAutoplay" :interval="interval"
  3. :duration="duration" @change='swiperChange'>
  4. <swiper-item v-for="(item,index) in list" :key="index" >
  5. <video-item v-if="item.type === 'video'"
  6. :videoAutoplay="videoAutoPlay"
  7. :poster="item.poster"
  8. :src="item.src" @play="handleVideoPlay" @pause="handleVideoPause"
  9. @ended="handleVideoEnd"></video-item>
  10. <image-item v-if="item.type === 'image'" :src="item.src"></image-item>
  11. </swiper-item>
  12. </swiper>
  13. </template>
  14. <script>
  15. import VideoItem from './components/video.vue';
  16. import ImageItem from './components/image.vue'
  17. export default {
  18. onShow: function() {
  19. },
  20. props: {
  21. list: {
  22. type: Array,
  23. default: () => {
  24. return [] //[{type:'video',src:''},{type:'image',src:''}]
  25. },
  26. required: true
  27. }
  28. },
  29. data() {
  30. return {
  31. //这里控制swiper
  32. indicatorDots: true,
  33. swiperAutoplay: true,
  34. interval: 4000,
  35. duration: 500,
  36. //以下是控制viedo的
  37. videoAutoPlay:false,
  38. }
  39. },
  40. components: {
  41. VideoItem,
  42. ImageItem
  43. },
  44. methods: {
  45. swiperChange(detail) {
  46. //切换时要把视频暂停
  47. this.videoAutoPlay = false;
  48. },
  49. handleVideoPlay() {
  50. this.swiperAutoplay = false
  51. this.videoAutoPlay = true;
  52. },
  53. handleVideoPause() {
  54. this.swiperAutoplay = true
  55. },
  56. handleVideoEnd() {
  57. this.swiperAutoplay = true;
  58. }
  59. },
  60. mounted() {
  61. }
  62. }
  63. </script>
  64. <style lang="scss">
  65. .swiper {
  66. width: (1080vw/10.8);
  67. height: (580vw/10.8);
  68. }
  69. </style>