npm install swiper@4.5 --save-dev
<template>
<div class="swiper-container">
<div class="swiper-wrapper">
<div class="swiper-slide">Slide 1</div>
<div class="swiper-slide">Slide 2</div>
<div class="swiper-slide">Slide 3</div>
</div>
<!-- 如果需要分页器 -->
<div class="swiper-pagination"></div>
<!-- 如果需要导航按钮 -->
<!-- <div class="swiper-button-prev"></div>
<div class="swiper-button-next"></div> -->
<!-- 如果需要滚动条 -->
<!-- <div class="swiper-scrollbar"></div> -->
</div>
</template>
<script>
// import { Swiper, SwiperSlide, directive } from 'vue-awesome-swiper'
// import Swiper from 'swiper';
import Swiper from 'swiper';
import "swiper/dist/css/swiper.min.css";
export default {
name: 'HelloWorld',
data () {
return {
msg: 'Welcome to Your Vue.js App'
}
},
mounted () {
this.openFullScreen()
var mySwiper = new Swiper('.swiper-container', {
// direction: 'vertical', // 垂直切换选项
// loop: true, // 循环模式选项
// mousewheel: true, //滚轮
// // observer: true,//修改swiper自己或子元素时,自动初始化swiper
// // observeParents: true,//修改swiper的父元素时,自动初始化swiper
// // slidesPerView: 'auto',
// // paginationClickable: true,
// // spaceBetween: 0,
// // 如果需要分页器
// pagination: {
// el: '.swiper-pagination',
// },
observer: true, //修改swiper自己或子元素时,自动初始化swiper
observeParents: true, //修改swiper的父元素时,自动初始化swiper
mousewheel: true,//开启鼠标滚轮控制滑动
mousewheel: {
releaseOnEdges: true,//PC端释放滑动
},
direction: 'vertical',
pagination: {
el: '.swiper-pagination',
clickable: true
},
speed: 1000
// // 如果需要前进后退按钮
// navigation: {
// nextEl: '.swiper-button-next',
// prevEl: '.swiper-button-prev',
// },
// // 如果需要滚动条
// scrollbar: {
// el: '.swiper-scrollbar',
// },
})
},
methods: {
openFullScreen () {
//loading加载页样式
const loading = this.$loading({
lock: true,
text: '',//loading加载信息
spinner: 'el-icon-loading',
background: 'rgba(0, 0, 0, 0.1)'
})
setTimeout(() => {
loading.close()
}, 100)//0.1s后清除,基本上肉眼不可见,不影响用户体验
}
}
}
</script>
<style scoped>
.swiper-container {
1000px;
height: 600px;
/* margin: 20px auto; */
background-color: red;
}
</style>