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

  • 相关阅读:
    二、线程的生命周期
    一、多线程基础
    Java中的三种代理模式(转载)
    SpringBoot+Thymeleaf实现国际化
    Centos7设置Jar包开机自启动
    Centos7安装及卸载RabbitMQ
    Nacos无法读取配置中心数据
    解决SSH连接Linux系统特别慢的问题
    KMP字符串匹配算法
    格雷厄姆扫描法解凸壳问题
  • 原文地址:https://www.cnblogs.com/karila/p/8137672.html
Copyright © 2011-2022 走看看