zoukankan      html  css  js  c++  java
  • vue 轮播插件使用

    <template>
    	<div>
    		 <Swiper ref="swiper" v-if="list.length > 0" :autoPlay='true' :showIndicator='true' interval="2500" duration="500">
    	        <Slide @click="clickMe" v-for="(tag,key) in list" :key="key">
    	        	<img :src="tag.img" />
    	        </Slide>
    	   </Swiper>
    	   <div><button @click="preve">上一张</button></div>
    	   <div><button @click="next">下一张</button></div>
       </div>
    </template>
    
    <script>
    		import { Swiper, Slide } from 'vue-swiper-component';
        export default {
            data() {
                return {
                    list: [
                        { img: 'https://qiniu.epipe.cn/5456575529551388672?imageslim&imageView2/1/w/750/h/360' },
                        { img: 'https://qiniu.epipe.cn/5430983074181545984?imageslim&imageView2/1/w/750/h/360' },
                        { img: 'https://qiniu.epipe.cn/5464226412548325376?imageslim&imageView2/1/w/750/h/360' }
                    ]
                }
            },
            components: {
    				    Swiper,
    				    Slide
    				},
            methods: {
                clickMe (index){
                		console.log(index)
                },
                preve(){
                	this.$refs.swiper.prevSlide();
                },
                next(){
                	this.$refs.swiper.nextSlide();
                }
                
            }
        }
    
    	
    </script>
    
    <style>
      img {
           100%;
      }
    
    .button {
        margin-top: 30px;
        position: relative;
        display: block;
        margin-left: auto;
        margin-right: auto;
        padding-left: 14px;
        padding-right: 14px;
        box-sizing: border-box;
        font-size: 18px;
        text-align: center;
        text-decoration: none;
        color: #ffffff;
        line-height: 2.33333333;
        border-radius: 5px;
        -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
        overflow: hidden;
        border- 0;
         50%;
        padding: 0 30px 0 30px;
        outline: 0;
        -webkit-appearance: none;
        background-color: #26a2ff;
    }
    
    .button:active {
        opacity: 0.5;
        color: #333;
    }
    
    .button2 {
        margin-top: 100px;
    }
    </style>
    

      参考地址

    https://github.com/zwhGithub/vue-swiper

    使用方法//

    npm i vue-swiper-component --save
    cnpm i vue-swiper-component --save  //国内镜像

    import { Swiper, Slide } from 'vue-swiper-component';
    
    components: {
        Swiper,
        Slide
    }

      //加一些参数配置情况
      <Swiper v-if="slidesReal.length > 0" :autoPlay='true' :showIndicator='true' interval="2500" duration="500">
            <Slide @click="clickMe" v-for="(tag,key) in slidesReal" :key="key">
            	//添加click事件
            </Slide>
       </Swiper>




    属性说明默认
    autoPlay 是否自动轮播 true
    showIndicator 是否显示轮播的那个点 true
    interval 每两次隔多久滚动一次 2500
    duration 每次滚动一页需要多久时间 500
     


    Swiper 上面还暴露了其他方法,在 Swiper 标签上添加 ref 属性, 例如: <Swiper ref="swiper"></Swiper>
    
        ✅  this.$refs.swiper.prevSlide(); // 上一张图
        ✅  this.$refs.swiper.nextSlide(); // 下一张图
        ✅  this.$refs.swiper.slideTo(2); //某一张图
  • 相关阅读:
    kernel list 实践
    rpm打包
    void out2() const{
    剑指offer python版 两个链表的第一个公共结点
    剑指offer python版 数组中的逆序对
    剑指offer python版 字符串中第一个只出现一次的字符
    剑指offer python版 丑数 (只含有2,3,5因子)
    剑指offer python版 最长不含重复字符的子字符
    剑指offer python版 礼物的最大价值
    剑指offer python版 数字序列中某一位的数字
  • 原文地址:https://www.cnblogs.com/qq735675958/p/8423277.html
Copyright © 2011-2022 走看看