Home  >  Article  >  Web Front-end  >  How to use swiper in vue.js

How to use swiper in vue.js

coldplay.xixi
coldplay.xixiOriginal
2020-11-10 13:53:321910browse

How to use swiper in vue.js: First download [swiper.js]; then introduce [swiper.js] globally in [main.js]; finally configure relevant content in the template.

How to use swiper in vue.js

【Related article recommendations: vue.js

Used in vue.js swiper method:

1. Download swiper.js

npm install vue-awesome-swiper --save

2. Globally introduce swiper.js in main.js

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

3. In the template Configuration related content

<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>

Related free learning recommendations:JavaScript(Video)

The above is the detailed content of How to use swiper in vue.js. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn