zoukankan      html  css  js  c++  java
  • vue vue-awesome-swiper首页轮播图的制作

    1.参考github地址https://github.com/surmon-china/vue-awesome-swiper

    首先安装插件

    npm install vue-awesome-swiper --save(建议安装2.6.7稳定版本)即
    npm install vue-awesome-swiper@2.6.7 --save

    2.在main.js引入插件

    import Vue from 'vue'
    //引入插件
    import VueAwesomeSwiper from 'vue-awesome-swiper'
    
    // require styles  引入样式
    import 'swiper/dist/css/swiper.css'
    //在全局使用该插件
    Vue.use(VueAwesomeSwiper, /* { default global options } */)

    3.编写轮播组件

    <!-- The ref attr used to find the swiper instance -->
    <template>
      <swiper :options="swiperOption" ref="mySwiper" @someSwiperEvent="callback">
        <!-- slides -->
        <swiper-slide>I'm Slide 1</swiper-slide>
        <swiper-slide>I'm Slide 2</swiper-slide>
        <swiper-slide>I'm Slide 3</swiper-slide>
        <swiper-slide>I'm Slide 4</swiper-slide>
        <swiper-slide>I'm Slide 5</swiper-slide>
        <swiper-slide>I'm Slide 6</swiper-slide>
        <swiper-slide>I'm Slide 7</swiper-slide>
        <!-- Optional controls 用于显示滚动叶下方的小点,需要在组件date里面将class名配置进去-->
        <div class="swiper-pagination"  slot="pagination"></div>
    //下面两个标签为轮播图两侧两个箭头,可以注释掉 <div class="swiper-button-prev" slot="button-prev"></div> <div class="swiper-button-next" slot="button-next"></div>
    //轮播图下方滚动条,可以注释掉 <div class="swiper-scrollbar" slot="scrollbar"></div> </swiper> </template> <script> export default { name: 'carrousel', data() { return { swiperOption: {
          swiperOption: ".swiper-pagination" // some swiper options/callbacks // 所有的参数同 swiper 官方 api 参数 // ... } } }, computed: { swiper() { return this.$refs.mySwiper.swiper } }, mounted() { // current swiper instance // 然后你就可以使用当前上下文内的swiper对象去做你想做的事了 console.log('this is current swiper instance object', this.swiper) this.swiper.slideTo(3, 1000, false) } } </script>

    <style lang="stylus" scoped>
    //样式穿透,对当前wraper下面的所有出现子组件swiper-pagination-bullet-active的样式全都改变,达到不受scoped限制的目的
      .wraper >>> .swiper-pagination-bullet-active
    background-color #fff
    .wraper
    overflow hidden
    widows: 100%
    height: 0
    padding-bottom 37.8%
    .swiper-img
    100%
    /*height: 0*/
    /*padding-bottom: */
    </style>
     


  • 相关阅读:
    当框架限制了我的想法,我选择Hack
    Ubuntu下自制douban.fm播放器
    如何让基于Swing的Java程序在Linux下看起来更和谐
    基于Bootstrap的黑色极简博客园主题
    spring boot引入外部jar包
    Spring缓存注解@CachePut , @CacheEvict,@CacheConfig使用
    【转】c#如何监视文件或者文件夹的变化
    【转】一些重要的计数器
    【原创】使用timer、imagelist与notifyicon控件实现图标闪烁并避免了GDI泄漏(重点)
    【转】全角字符与半角字符的相互转换(C#)
  • 原文地址:https://www.cnblogs.com/mingbo-zhang/p/9744449.html
Copyright © 2011-2022 走看看