Home > Article > Web Front-end > How to use swiper in vue.js
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.
【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+ '/resources/img/' + item.imgPath"/> </swiper-slide> <div class="swiper-pagination" slot="pagination"></div> </swiper> </template> <script> import axios from 'axios' export default { name: 'carrousel', data() { return { rootLink: 'http://119.23.28.239:8080', imglist:[], swiperOption: { autoplay: 3000, //l轮播间隔时间 loop: true, //是否自动轮播 pagination : '.swiper-pagination', //轮播图中下标点显示 paginationClickable :true //轮播图中下标点显示 } } }, mounted() { var vm = this; axios.get(vm.rootLink + '/train/homePage/banner?type=上面') .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!