封装
<template>
<view>
<swiper :indicator-dots="isShowDot && showDot" class="swiper" :style="{height:(145*col)+'rpx'}">
<swiper-item v-for="(item, index) in listdivInfo" :key="index" class="swiper-item">
<view v-for="(child, code) in item" class="smallItem" :key="code" :style="{ width: width + '%' }">
<view class="image">
<u-image :src="imageURL(child.image)" width="64rpx" height="64rpx" radius="32rpx">
</u-image>
</view>
<view class="name">{{ child.title }}</view>
</view>
</swiper-item>
</swiper>
</view>
</template>
<script>
export default {
props: {
list: {
type: Array,
default: () => {
return [];
},
},
//一行排列数
nums: {
type: Number,
default: 4,
},
//排列行数
col: {
type: Number,
default: 1,
},
//是否展示指示灯
isShowDot: {
type: Boolean,
default: true,
},
},
watch: {
list: {
handler: function (newVal, oldVal) {
this.listdiv();
},
deep: true,
},
},
mounted() {
this.listdiv();
},
data() {
return {
listdivInfo: [],
width: 25,
showDot: true,
};
},
methods: {
async listdiv() {
this.width = 100 / this.nums;
var arr = [];
let that = this;
console.log(that.nums * that.col);
await this.list.forEach((v, index) => {
var num = Math.floor(index / (that.nums * that.col));
if (!arr[num]) {
arr[num] = [];
arr[num].push(v);
} else {
arr[num].push(v);
}
});
this.listdivInfo = arr;
if (this.listdivInfo.length > 1) {
this.showDot = true;
} else {
this.showDot = false;
}
},
},
};
</script>
<style lang="scss" scoped>
.swiper {
margin: 8rpx 32rpx;
background: white;
border-radius: 32rpx;
}
.swiper-item {
display: flex;
flex-wrap: wrap;
.smallItem {
display: flex;
flex-direction: column;
align-items: center;
margin: 16rpx 0;
overflow: hidden;
image {
width: 64rpx;
height: 64rpx;
}
.name {
margin-top: 8rpx;
font-size: 16rpx;
}
}
}
</style>
使用文章来源:https://www.toymoban.com/news/detail-518357.html
<template>
<view>
<scrollX :list="cateList" :nums="5" :col="2" />
</view>
</template>
<script>
import scrollX from "@/components/scroll-x/index.vue";
export default {
components: {
scrollX
},
data() {
return {
cateList: [
{
title: "酒店民宿",
image: "图片地址",
path: "",
isPath: true,
},
{
title: "健康医疗",
image: "",
path: "",
isPath: true,
},
]
}
},
}
</script>
注:可自行修改数据格式文章来源地址https://www.toymoban.com/news/detail-518357.html
到了这里,关于uniapp 自定义横向滑动列表(金刚区,类似于美团小程序首页顶部)的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!