标签:oba add pad dde scrollbar 参考 optional ext bullet
1.参考github地址https://github.com/surmon-china/vue-awesome-swiper
首先安装插件
npm install vue-awesome-swiper --save(建议安装2.6.7稳定版本)即
npm install vue-awesome-swiper@2.6.7 --save
2.在main.js引入插件
import Vue from ‘vue‘
//引入插件
import VueAwesomeSwiper from ‘vue-awesome-swiper‘
// require styles 引入样式
import ‘swiper/dist/css/swiper.css‘
//在全局使用该插件
Vue.use(VueAwesomeSwiper, /* { default global options } */)
3.编写轮播组件
<!-- The ref attr used to find the swiper instance -->
<template>
<swiper :options="swiperOption" ref="mySwiper" @someSwiperEvent="callback">
<!-- slides -->
<swiper-slide>I‘m Slide 1</swiper-slide>
<swiper-slide>I‘m Slide 2</swiper-slide>
<swiper-slide>I‘m Slide 3</swiper-slide>
<swiper-slide>I‘m Slide 4</swiper-slide>
<swiper-slide>I‘m Slide 5</swiper-slide>
<swiper-slide>I‘m Slide 6</swiper-slide>
<swiper-slide>I‘m Slide 7</swiper-slide>
<!-- Optional controls 用于显示滚动叶下方的小点,需要在组件date里面将class名配置进去-->
<div class="swiper-pagination" slot="pagination"></div>
//下面两个标签为轮播图两侧两个箭头,可以注释掉
<div class="swiper-button-prev" slot="button-prev"></div>
<div class="swiper-button-next" slot="button-next"></div>
//轮播图下方滚动条,可以注释掉
<div class="swiper-scrollbar" slot="scrollbar"></div>
</swiper>
</template>
<script>
export default {
name: ‘carrousel‘,
data() {
return {
swiperOption: {
swiperOption: ".swiper-pagination"
// some swiper options/callbacks
// 所有的参数同 swiper 官方 api 参数
// ...
}
}
},
computed: {
swiper() {
return this.$refs.mySwiper.swiper
}
},
mounted() {
// current swiper instance
// 然后你就可以使用当前上下文内的swiper对象去做你想做的事了
console.log(‘this is current swiper instance object‘, this.swiper)
this.swiper.slideTo(3, 1000, false)
}
}
</script>
<style lang="stylus" scoped>
//样式穿透,对当前wraper下面的所有出现子组件swiper-pagination-bullet-active的样式全都改变,达到不受scoped限制的目的
.wraper >>> .swiper-pagination-bullet-active
background-color #fff
.wraper
overflow hidden
widows: 100%
height: 0
padding-bottom 37.8%
.swiper-img
width: 100%
/*height: 0*/
/*padding-bottom: */
</style>
vue vue-awesome-swiper首页轮播图的制作
标签:oba add pad dde scrollbar 参考 optional ext bullet
原文地址:https://www.cnblogs.com/mingbo-zhang/p/9744449.html