vue.js怎么用swiper

vue.js中使用swiper的方法:首先下载【swiper.js】;然后在【main.js】中全局引入【swiper.js】;最后在模板中配置相关内容即可。

vue.js怎么用swiper

【相关文章推荐:vue.js

vue.js中使用swiper的方法:

1、下载swiper.js

npm install vue-awesome-swiper --save

2、在main.js中全局引入swiper.js

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

3、在模板中配置相关内容

<template>
  <swiper :options="swiperOption">
    <swiper-slide v-for="item in imglist">
      <img :src="rootLink+ &#39;/resources/img/&#39; + item.imgPath"/>
    </swiper-slide>
    <div class="swiper-pagination" slot="pagination"></div>
  </swiper>
</template>
<script>
import axios from &#39;axios&#39;
export default {
  name: &#39;carrousel&#39;,
  data() {
    return {
      rootLink: &#39;http://119.23.28.239:8080&#39;,
      imglist:[],
      swiperOption: {
        autoplay: 3000,  //l轮播间隔时间
        loop: true,  //是否自动轮播
        pagination : &#39;.swiper-pagination&#39;, //轮播图中下标点显示
        paginationClickable :true   //轮播图中下标点显示
      }
     }
  },
  mounted() {
    var vm = this;
    axios.get(vm.rootLink + &#39;/train/homePage/banner?type=上面&#39;)
    .then(function (data) {
      vm.imglist = data.data.data
    })
  }
}
</script>

相关免费学习推荐:JavaScript(视频)

以上就是vue.js怎么用swiper的详细内容,更多请关注www.sxiaw.com其它相关文章!