您好,登錄后才能下訂單哦!
這篇文章主要介紹了vue使用原生swiper代碼實例,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下
代碼如下
<template> <div> <div class="swiper_Box" :class="identify"> <div class="swiper-wrapper" :ref="identify"> <div class="swiper-slide" v-for="(item,index) in imgArr" :key="'swiperSlide'+index"> <div class="bannerItem"> <img :src="item.url" alt=""> </div> </div> </div> <!-- <div v-if="imgArr.length>1" class="swiper-button-prev" slot="button-prev"></div> <div v-if="imgArr.length>1" class="swiper-button-next" slot="button-next"></div> --> <div class="swiper-pagination"></div> </div> </div> </template> <script> export default { props:['imgArr','identify','paginationType'],//接收傳來的輪播圖 watch:{ imgArr:{ handler(newVal){ console.log(newVal) }, immediate:true }, identify:{ handler(newVal){ console.log("id:"+newVal) var self=this; }, immediate:true } }, data(){ return{ swiperShow:false, MySwiper:null,//swiper實例 } }, created(){ }, mounted(){ var self=this; self.MySwiper = new Swiper ('.'+self.identify,{ init: true, observer:true, observeParents:true, slidesPerView: 1, spaceBetween: 0, keyboard: { enabled: true, }, loop: true, autoplay: { delay: 8000, disableOnInteraction: false }, pagination: { el: '.swiper-pagination', clickable: true, type:self.paginationType?self.paginationType:'bullets' }, navigation: { nextEl: '.swiper-button-next', prevEl: '.swiper-button-prev' }, }); } } </script> <style scoped> @import url("../styles/swiperBullet.css"); /* 輪播圖 */ .swiperBox{ width:100%; } .swiper_Box{ position: relative; overflow: hidden; } .swiper_Box .bannerItem img{ height:auto; width:100%; } .swiperBox .bannerItem{ width:100%; text-align: center; } .swiperBox .bannerItem img{ height:auto; width:100%; } .swiper-pagination{ position: absolute; bottom:20px; left:50%; transform: translateX(-50%); } </style>
swiper的引入形式是link標簽引入樣式
script標簽引入js
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持億速云。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。