vue中引入swiper(vue中的滑塊組件vue-awesome-swiper)


第一步安裝

npm install vue-awesome-swiper --save

第二部在main.js中引入

import VueAwesomeSwiper from 'vue-awesome-swiper'
Vue.use(VueAwesomeSwiper)

然后就可以在組件中使用該插件

  1. <template>  
  2.     <div>  
  3.         <swiper :options="swiperOption"  ref="mySwiper">  
  4.             <!-- 這部分放你要渲染的那些內容 -->  
  5.             <swiper-slide v-for="item in items">  
  6.             </swiper-slide>  
  7.             <!-- 這是輪播的小圓點 -->  
  8.             <div class="swiper-pagination" slot="pagination"></div>  
  9.         </swiper>  
  10.     </div>  
  11. </template>  
  12. <script>  
  13.     import { swiper, swiperSlide } from 'vue-awesome-swiper'  
  14.     export default {  
  15.         components: {  
  16.             swiper,  
  17.             swiperSlide  
  18.         },  
  19.         data() {  
  20.             return {  
  21.                 swiperOption: {  
  22.                 //是一個組件自有屬性,如果notNextTick設置為true,組件則不會通過NextTick來實例化swiper,也就意味着你可以在第一時間獲取到swiper對象,假如你需要剛加載遍使用獲取swiper對象來做什么事,那么這個屬性一定要是true  
  23.                 notNextTick: true,  
  24.                 pagination: '.swiper-pagination',  
  25.                 slidesPerView: 'auto',  
  26.                 centeredSlides: true,  
  27.                 paginationClickable: true,  
  28.                 spaceBetween: 30,  
  29.                     onSlideChangeEnd: swiper => {  
  30.                         //這個位置放swiper的回調方法  
  31.                         this.page = swiper.realIndex+1;  
  32.                         this.index = swiper.realIndex;  
  33.                     }  
  34.                 }  
  35.             }  
  36.         }
  37.     }  
  38. </script>  
  39. <style>  
  40. </style>  


免責聲明!

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



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