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>  

转载于:https://www.cnblogs.com/cina33blogs/p/6760820.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值