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+ '/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>