vue-awesome-swiper

坚强是说给别人听的谎言 提交于 2019-11-27 10:47:52

npm install vue-awesome-sw

 1 main.jsimport VueAwesomeSwiper from 'vue-awesome-swiper'Vue.use(VueAwesomeSwiper)<template>
 2   <div>
 3     <swiper :options="swiperOption" ref="mySwiper">
 4      <!-- 务必加上key 2.0后-->
 5       <swiper-slide v-for="(item,index) in recommends" :key="index">
 6         <img :src="item.picUrl">
 7       </swiper-slide>
 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 require('swiper/dist/css/swiper.css')//必须 不然样式不能生效
15 export default {
16   data () {
17     return {
18       swiperOption: {
19         notNextTick: true,
20         autoplay: 3000,
21         pagination: '.swiper-pagination',
22         paginationClickable: true,
23         mousewheelControl: true,
24         autoplayDisableOnInteraction: false,//移动端加上这个不然不会滚动
25         loop: true,//环路
26         observeParents: true,
27         onSlideChangeEnd: swiper => {
28           this.page = swiper.realIndex + 1
29           this.index = swiper.realIndex
30         }
31       }
32     }
33   },
34   components: {
35     swiper,
36     swiperSlide
37   },
38   computed: {
39     swiper () {
40       return this.$refs.mySwiper.swiper
41     }
42   },
43   mounted () {
44     this.swiper.slideTo(0, 0, false)
45   }
46 }
47 
48 </script>

 

iper --save

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!