代码:(vue分页的代码也是如下,只要把view标签换成div或其它标签,然后把upx单位换成px即可)
<template>
<view class="box">
<view class="swiper-box" v-for="(page,index) of pages" :key="index">
<view class="icon" v-for="item of page" :key="item.id">
<view class="a-icon">
{{item}}
</view>
</view>
</view>
</view>
</template>
<script>
export default {
data() {
return {
list: [
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13
]
};
},
computed: {
// 通过计算属性实现分页逻辑
pages() {
const pages = []
this.list.forEach((item, index) => {
// 向下取整(一页显示3个数据),page代表页数
const page = Math.floor(index / 3)
if (!pages[page]) {
pages[page] = []
}
pages[page].push(item)
});
return pages
}
}
}
</script>
<style lang="scss">
.box{ margin: 40upx auto; }
.swiper-box{
width: 90vw;
background: pink;
text-align: center;
margin: 30upx;
.icon{
border-bottom: 1px solid red;
padding: 30upx 0;
font-size: 36upx;
}
}
</style>
效果图: