zoukankan      html  css  js  c++  java
  • vue2中用swiper

    一、安装swiper

    npm install --save swiper
    

     

    二、home组件 

    //home.js

    <app-banner :listImg="bannerList"></app-banner> 传值:bannerList为传入的数组 引入 import Banner from '../components/banner.vue' 模块化 components: { 'app-banner': Banner },

      

    三、子组件

    banner.js
    
    <template>
      <div class="swiper-container">
        <div class="swiper-wrapper">
          <div class="swiper-slide" v-for="str in listImg" :style="{ backgroundImage: 'url(' + str.img_url + '?imageView2/2/w/640/h/400)' }">
            <img :src="str.img_url" alt="">
          </div>
        </div>
        <div class="swiper-pagination swiper-pagination-white"></div>
      </div>
    </template>
    
    <script>
      import Swiper from 'swiper';
      //import 'swiper/dist/css/swiper.min.css';
      import '../assets/css/swiper.min.css';
      export default {
        props: ['listImg'],
        mounted() {
          console.log('mounted', this)
          var swiper = new Swiper('.swiper-container', {
            pagination: '.swiper-pagination',
            paginationClickable: true,
            loop: true,
            speed: 600,
            autoplay: 4000,
            observer:true,//修改swiper自己或子元素时,自动初始化swiper
            observeParents:true,//修改swiper的父元素时,自动初始化swiper
            onTouchEnd: function() {
              swiper.startAutoplay()
            }
          });
        }
      }
    </script>
    
    
    <style scoped>
      .swiper-container {
         100%;
        height: 4rem;
      }
      .swiper-wrapper {
         100%;
        height: 100%;
      }
      .swiper-slide {
        background-position: center;
        background-size: cover;
         100%;
        height: 100%;
    
      }
      .swiper-slide img{
         100%;
        height: 100%;
        max-height:4rem;
      }
      .swiper-pagination-bullet {
        0.833rem;
        height: 0.833rem;
        display: inline-block;
        background: #7c5e53;
      }
    
    </style>
    

      

    原文链接:https://segmentfault.com/a/1190000009143923

                    https://segmentfault.com/a/1190000002962202

  • 相关阅读:
    11、旋转图像
    10、有效的数独
    9、两数之和
    8、移动零
    6、两个数组的交集 II
    7、加一
    5、只出现一次的数字
    3、旋转数组
    spring快速复习
    mybatis XML SQL基本配置
  • 原文地址:https://www.cnblogs.com/karila/p/8137672.html
Copyright © 2011-2022 走看看