viewimg.vue 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <template>
  2. <div class="imgcon">
  3. <div class="swiper-container" :class="keyid" >
  4. <ul class="swiper-wrapper imgul">
  5. <li class="swiper-slide img" v-for="(pic, picii) in list" :key="picii" :style="{ backgroundImage: `url(${pic})` }"></li>
  6. </ul>
  7. <ul class="pagination">
  8. <li :class="{active:picii==current}" v-for="(pic, picii) in list" :key="picii"></li>
  9. </ul>
  10. </div>
  11. </div>
  12. </template>
  13. <script setup>
  14. import { ref, watch, defineEmits, computed, onMounted, nextTick, defineProps } from "vue";
  15. const current = ref(0)
  16. const props = defineProps({
  17. list: {
  18. type: Array,
  19. default: [],
  20. },
  21. keyid:{
  22. type: String,
  23. default: 'keyid',
  24. }
  25. });
  26. const initScroll = () => {
  27. nextTick(() => {
  28. let t = setTimeout(() => {
  29. clearTimeout(t);
  30. console.log(props.keyid);
  31. new Swiper(`.${props.keyid}`, {
  32. on: {
  33. touchMove(swiper, e) {
  34. e.stopPropagation();
  35. e.preventDefault();
  36. },
  37. slideChange() {
  38. current.value = this.activeIndex;
  39. },
  40. },
  41. });
  42. }, 100);
  43. });
  44. };
  45. onMounted(() => {
  46. initScroll();
  47. });
  48. </script>
  49. <style lang="scss" scoped>
  50. .imgcon{
  51. min-height: 34vh;
  52. .swiper-container {
  53. position: relative;
  54. .imgul {
  55. .img {
  56. height: 34vh;
  57. width: 100%;
  58. background-size: auto 100%;
  59. background-position: center;
  60. }
  61. }
  62. .pagination{
  63. position: absolute;
  64. left: 50%;
  65. bottom: 10px;
  66. transform: translateX(-50%);
  67. z-index: 99;
  68. >li{
  69. width: 8px;
  70. height: 8px;
  71. margin: 0 4px;
  72. display: inline-block;
  73. border-radius: 50%;
  74. background-color: rgba(0, 0, 0, 0.2);
  75. &.active{
  76. background-color: var(--editor-main-color);
  77. }
  78. }
  79. }
  80. }
  81. }
  82. </style>