vue 組件式開發swiper

29 篇文章 0 订阅

必須要先安裝npm install  vue-awesome-swiper

//組件
<template>
    <div class="my-swiper">
    <swiper :optops="swiperOption" class="swiper-menu">
      <swiper-slide><img src="~assets/img/home.png" alt=""/></swiper-slide>
      <swiper-slide><img src="~assets/img/home_1.png" alt=""/></swiper-slide>
      <swiper-slide><img src="~assets/img/home_3.png" alt=""/></swiper-slide>
      <div class="swiper-scrollbar" slot="scrollbar"></div>
    </swiper>
    </div>
  </div>
  
</template>


<script>

export default {
  name:'MySwiper',
  data(){
    return{
      swiperOption:{
        loop:true
      }
    }
  }
  
}
</script>

<style>
    .my-swiper {
      width: 100%;
      height: 100%;
    }
    .swiper-slide img{
      overflow: hidden;
      width: 100%;
      height: 100%;;
      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;
      padding: 3px;
      border-bottom: 1px solid #ffffff

    }

</style>

 

//父組件使用
<div class="home-view">
      <my-swiper></my-swiper>
      <feature class="feature"></feature>
    </div>   


import MySwiper from '../swiper/Swiper'

 swiper作為組件應該是由父組件來控制是圖片還是其他控件 ,然後在基礎上進行封裝

//父組件 

 <swiper :optops="swiperOption" class="swiper-menu">
      <swiper-slide><img src="~assets/img/home.png" alt=""/></swiper-slide>
      <swiper-slide><img src="~assets/img/home_3.png" alt=""/></swiper-slide>
      <swiper-slide><img src="~assets/img/home_1.png" alt=""/></swiper-slide>
      <div class="swiper-scrollbar" slot="scrollbar"></div>
 </swiper>




//子組件,使用插槽方式,方便父子件安裝需求添加所需的控件

<swiper>
      <swiper-slide><slot></slot></swiper-slide>
      <swiper-slide><slot></slot></swiper-slide>
      <swiper-slide><slot></slot></swiper-slide>
      <div class="swiper-scrollbar" slot="scrollbar"></div>
    </swiper>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值