一个小轮播图

简介: 一个小轮播图

用VUE3+Swipe实现了一个带缩略图的轮播图 展示为


代码如下:


<div class="swiper-box">
            <swiper :navigation="true" :modules="modules" class="mySwiper2" :loop="true"
              :thumbs="{ swiper: thumbsSwiper }">
              <swiper-slide v-for="item in supplyImg" :key="item">
                <img :src="item" alt="">
              </swiper-slide>
            </swiper>
            <swiper @swiper="setThumbsSwiper" :loop="true" :spaceBetween="10" :slidesPerView="3" :freeMode="true"
              :watchSlidesProgress="true" :modules="modules" class="mySwiper">
              <swiper-slide v-for="item in supplyImg" :key="item">
                <img :src="item" alt="">
              </swiper-slide>
            </swiper>
          </div>



export default {
    components: {
      Swiper,
      SwiperSlide,
    },
    setup () {
      const supplyData = ref({})
      const route = useRoute()
      const supplyId = route.params.supply_id
      const supplyImg = ref([])
      const supplyDetail = () => {
        console.log("supplyCategory~");
        getSupplynDetail(
          {
            supply_info: {
              supply_id: supplyId
            }
          },
          (status, res, data) => {
            supplyData.value = data.supply_infos[0]
            supplyImg.value = JSON.parse(supplyData.value.supply_scroll_images)
            console.log("supplyImg", supplyImg.value);
          },
          (status, error, msg) => {
            console.log('status: ', status)
            console.log('error: ', error)
            console.log('msg: ', msg)
            PromptMessage.messageBoxError('错误提示', msg)
          }
        )
      }
      let thumbsSwiper = ref(null);
      const setThumbsSwiper = (swiper) => {
        thumbsSwiper.value = swiper;
      }
      return {
        rate, modules: [Navigation, FreeMode, Thumbs],
        supplyDetail, supplyData, supplyId, supplyImg, thumbsSwiper, setThumbsSwiper
      }
    },
    mounted () {
      this.supplyDetail()
    }
  }



.swiper-box {
      width: 100%;
      height: 100%;
      margin-left: auto;
      margin-right: auto;
      margin-top: 30px;
      .swiper-slide {
        text-align: center;
        font-size: 18px;
        // background: #fff;
        /* Center slide text vertically */
        display: -webkit-box;
        display: -ms-flexbox;
        display: -webkit-flex;
        display: flex;
        -webkit-box-pack: center;
        -ms-flex-pack: center;
        -webkit-justify-content: center;
        justify-content: center;
        -webkit-box-align: center;
        -ms-flex-align: center;
        -webkit-align-items: center;
        align-items: center;
        background-size: cover;
        background-position: center;
        img {
          display: block;
          width: 100%;
          height: 100%;
          object-fit: cover;
        }
      }
      .mySwiper2 {
        position: relative;
        // float: left;
        height: 100%;
        width: 100%;
        border-radius: 12px;
      }
      .mySwiper {
        position: relative;
        margin-top: 5%;
        float: left;
        // margin-left: 3%;
        width: 100%;
        height: 70%;
        box-sizing: border-box;
        padding: 10px 0;
        .swiper-slide {
          width: 100%;
          height: 33%;
          opacity: 0.4;
          img {
            border-radius: 4%;
          }
        }
        .swiper-slide-thumb-active {
          opacity: 1;
        }
      }
      .swiper-cover {
        position: absolute;
        width: 100%;
        height: 30%;
        background-color: rgba(0, 0, 0, 0.6);
        bottom: 0%;
        right: 0%;
        z-index: 100;
      }
      .swipercover-top {
        margin-left: 5%;
        margin-right: 5%;
        width: 90%;
        height: 30%;
        color: white;
        border-bottom: 2px solid dodgerblue
      }
      .swipercover-top-text {
        width: 15%;
        height: 100%;
        border-bottom: 2px solid red;
        display: flex;
        align-items: center;
        justify-content: center;
      }
      .swipercover-bottom {
        margin-left: 10%;
        width: 100%;
        height: 70%
      }
    }



相关文章
|
9月前
|
JavaScript
uniapp写轮播图?
uniapp写轮播图?
|
9月前
|
JavaScript 前端开发
原生js做轮播图
原生js做轮播图
37 0
|
JavaScript 容器
使用 swiper 做轮播图
使用 swiper 做轮播图
839 0
使用 swiper 做轮播图
轮播图片上添加描述
在轮播图片中添加描述,通过在每个`&lt;div class=&quot;carousel-item&quot;&gt;`内加入`&lt;div class=&quot;carousel-caption&quot;&gt;`来设置图片描述。示例展示了如何为轮播图添加标题和内容,并介绍了相关类的作用,如`.carousel`创建轮播、`.carousel-indicators`添加指示符等,实现图片的切换及动画效果。
轮播图片上添加描述
|
4月前
“节流阀“ 在轮播图的使用
“节流阀“ 在轮播图的使用
36 1
|
5月前
|
JavaScript 索引
轮播图,用vue来写一个简单的轮播图
本文介绍了如何使用Vue.js编写一个简单的轮播图功能,包括左右箭头的点击事件处理和使用v-bind、v-show指令进行图片地址绑定和箭头显示隐藏的逻辑。
轮播图,用vue来写一个简单的轮播图
|
8月前
|
安全 JavaScript
旋转木马轮播图 html+css+js
旋转木马轮播图 html+css+js
|
8月前
|
前端开发 UED
CSS动画(轮播图)
CSS动画(轮播图)
|
9月前
|
JavaScript 前端开发 索引
用四种方法实现轮播图
用四种方法实现轮播图
196 0
|
9月前
|
前端开发 JavaScript
轮播图的实现
轮播图的实现
61 0