Vue中使用swiper插件實現輪播圖


 1 <template>
 2   <div class="HeadRotation">
 3 <!-- 列表輪播圖 -->
 4     <div class="swiper-container qwe">
 5       <div class="swiper-wrapper">
 6         <div class="swiper-slide">
 7              <img :src="image" alt="圖片未加載">
 8         </div>
 9         <div class="swiper-slide">
10             <img :src="image1" alt="圖片未加載">
11         </div>
12       </div>
13       <!-- 如果需要分頁器 -->
14       <div class="swiper-pagination paging"></div>
15 
16       <!-- 如果需要導航按鈕 -->
17       <div class="swiper-button-prev"></div>
18       <div class="swiper-button-next"></div>
19 
20       <!-- 如果需要滾動條 -->
21       <!-- <div class="swiper-scrollbar"></div> -->
22     </div>
23   </div>
24 </template>
25 
26 <script>
//局部引入swiper插件 27 import Swiper from "swiper"; 28 import "swiper/css/swiper.min.css"; 29 export default { 30 name: "HeadRotation", 31 data () { 32 return { 33 image: require("../../assets/images/img_banner.jpg"), 34 image1: require("../../assets/images/img_banner1.jpg") 35 36 } 37 }, 38 39 mounted() { 40 new Swiper ('.qwe', { 41 42 loop: true, // 循環模式選項 43 autoplay: true,//自動循環 44 45 // 如果需要分頁器 46 pagination: { 47 el: '.paging', 48 }, 49 50 // 如果需要前進后退按鈕 51 navigation: { 52 nextEl: '.swiper-button-next', 53 prevEl: '.swiper-button-prev', 54 }, 55 56 // 如果需要滾動條 57 // scrollbar: { 58 // el: '.swiper-scrollbar', 59 // }, 60 }) 61 62 }, 63 64 }; 65 </script> 66 67 <style lang="scss" scoped> 68 .banner { 69 width: 100%; 70 } 71 .swiper-slide img { 72 width: 100%; 73 min-width: 1200px; 74 height: 100%; 75 } 76 </style>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM