一. 演示图
1571385982(1).png二.在vue项目中引入
命令行 npm install swiper --save
html:
<div class="swiper-container">
<div class="swiper-wrapper">
<div class="swiper-slide">
<a href="javascript:" class="link_to_food">
<div class="food_container">
<img src="./images/nav/1.jpg" />
</div>
<span>甜品饮品</span>
</a>
<a href="javascript:" class="link_to_food">
<div class="food_container">
<img src="./images/nav/2.jpg" />
</div>
<span>商超便利</span>
</a>
<a href="javascript:" class="link_to_food">
<div class="food_container">
<img src="./images/nav/3.jpg" />
</div>
<span>美食</span>
</a>
<a href="javascript:" class="link_to_food">
<div class="food_container">
<img src="./images/nav/4.jpg" />
</div>
<span>简餐</span>
</a>
<a href="javascript:" class="link_to_food">
<div class="food_container">
<img src="./images/nav/5.jpg" />
</div>
<span>新店特惠</span>
</a>
<a href="javascript:" class="link_to_food">
<div class="food_container">
<img src="./images/nav/6.jpg" />
</div>
<span>准时达</span>
</a>
<a href="javascript:" class="link_to_food">
<div class="food_container">
<img src="./images/nav/7.jpg" />
</div>
<span>预订早餐</span>
</a>
<a href="javascript:" class="link_to_food">
<div class="food_container">
<img src="./images/nav/8.jpg" />
</div>
<span>土豪推荐</span>
</a>
</div>
<div class="swiper-slide">
<a href="javascript:" class="link_to_food">
<div class="food_container">
<img src="./images/nav/9.jpg" />
</div>
<span>甜品饮品</span>
</a>
<a href="javascript:" class="link_to_food">
<div class="food_container">
<img src="./images/nav/10.jpg" />
</div>
<span>商超便利</span>
</a>
<a href="javascript:" class="link_to_food">
<div class="food_container">
<img src="./images/nav/11.jpg" />
</div>
<span>美食</span>
</a>
<a href="javascript:" class="link_to_food">
<div class="food_container">
<img src="./images/nav/12.jpg" />
</div>
<span>简餐</span>
</a>
<a href="javascript:" class="link_to_food">
<div class="food_container">
<img src="./images/nav/13.jpg" />
</div>
<span>新店特惠</span>
</a>
<a href="javascript:" class="link_to_food">
<div class="food_container">
<img src="./images/nav/14.jpg" />
</div>
<span>准时达</span>
</a>
<a href="javascript:" class="link_to_food">
<div class="food_container">
<img src="./images/nav/1.jpg" />
</div>
<span>预订早餐</span>
</a>
<a href="javascript:" class="link_to_food">
<div class="food_container">
<img src="./images/nav/2.jpg" />
</div>
<span>土豪推荐</span>
</a>
</div>
</div>
<!-- Add Pagination -->
<div class="swiper-pagination"></div>
</div>
css:
.swiper-container {
width: 100%;
height: 100%;
.swiper-wrapper {
width: 100%;
height: 100%;
.swiper-slide {
display: flex;
justify-content: center;
align-items: flex-start;
flex-wrap: wrap;
.link_to_food {
width: 25%;
.food_container {
display: block;
width: 100%;
text-align: center;
padding-bottom: 10px;
font-size: 0;
img {
display: inline-block;
width: 50px;
height: 50px;
}
}
span {
display: block;
width: 100%;
text-align: center;
font-size: 13px;
color: #666;
}
}
}
}
.swiper-pagination {
>span.swiper-pagination-bullet-active {
background: #02a774;
}
}
}
js中:
import Swiper from 'swiper';
import "swiper/css/swiper.min.css"
mounted() {
new Swiper(".swiper-container", {
loop: true, // 循环模式选项
// 如果需要分页器
pagination: {
el: ".swiper-pagination"
}
});
}
三. 特别说明
js中创建一个swiper对象,第一个参数为选择器(和html中一致即可),第二参数为对象构造函数。
在html中标签中需含swipe-slide,代表每一页,填入内容即可
网友评论