uni-app商城(三)首页

1.首页代码

<template>
	<view>
		<!-- 轮播图 -->
		<swiper :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000">
			<swiper-item v-for="(item,i) in swiperList" :key="i">
				<navigator class="swiper-item" :url="'../../subpkg/productDetail/productDetail?id='+item.id">
					<image :src="item.imageSrc" mode="scaleToFill"></image>
				</navigator>
			</swiper-item>
		</swiper>
		<!-- 分类导航 -->
		<view class="nav-list">
			<view class="nav-item" v-for="(item,i) in navList" :key="i" @click="navClickHandler(item)">
				<image :src="item.imageSrc" mode="scaleToFill"></image>{{item.name}}
			</view>
		</view>
		<!-- 楼层数据 -->
		<view class="floor-list">
			<view class="floor-item" v-for="(item,i) in floorList" :key="i">
				<!-- 楼层标题 -->
				<image :src="item.imageSrc" class="floor-title"></image>
				<view class="floor-img-box">
					<!-- 左侧图 -->
					<navigator class="left-img-box" :url="item.products[0].url">
						<image src="../../static/home/floor/imgbox/优质服饰.png" mode="widthFix" style="width: 232rpx;">
						</image>
					</navigator>
					<!-- 右侧图 -->
					<view class="right-img-box">
						<navigator  :url="item.products[0].url" class="right-img-item" v-for="(item2,i2) in item.products" :key="i2" v-if="i2!==0">
							<image :src="item2.imageSrc" mode="widthFix" style="width: 232rpx;"></image>
						</navigator>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				//轮播图数据
				swiperList: [],
				//分类导航数据
				navList: [],
				// 楼层数据
				floorList: []
			}
		},
		onLoad() {
			//轮播图数据
			this.getSwiperList()
			//分类导航数据
			this.getNavList()
			// 楼层数据
			this.getFloorList()
		},
		methods: {
			getSwiperList() {
				uni.request({
						url: uni.$baseUrl + '/api/Home/GetSwiperList',
					})
					.then((res) => {
						// console.log(res.data.data);
						if (res.data.code != 200) return uni.$showMsg();
						this.swiperList = res.data.data;
					});
			},
			getNavList() {
				uni.request({
						url: uni.$baseUrl + '/api/Home/GetNavList',
					})
					.then((res) => {
						// console.log(res.data.data);
						if (res.data.code != 200) return uni.$showMsg();
						this.navList = res.data.data;
					});
			},
			getFloorList() {
				uni.request({
						url: uni.$baseUrl + '/api/Home/GetFloorList',
					})
					.then((res) => {
						// console.log(res.data.data);
						if (res.data.code != 200) return uni.$showMsg();
						res.data.data.forEach(floor=>{
							floor.products.forEach(prod=>{
								prod.url='/subpkg/goods_list/goods_list?'+prod.name
							})
						})
						this.floorList = res.data.data;
					});
			},
			navClickHandler(item) {
				if (item.name == '全部分类')
					uni.switchTab({
						url: '/pages/cate/cate'
					})
			}
		}
	}
</script>

<style lang="scss">
	swiper {
		width: 100%;

		.swiper-item image {
			width: 100%;
		}
	}

	.nav-list {
		display: flex;
		justify-content: space-around;
		margin: 10rpx;
		font-size: 14px;
		text-align: center;

		.nav-item image {
			display: flex;
			justify-content: center;
			width: 110rpx;
			height: 110rpx;
		}
	}


	.floor-title {
		width: 100%;
		height: 60rpx;
	}
	.floor-img-box {
		display: flex;
		padding-left: 10rpx;
	}
	.right-img-box {
		display: flex;
		flex-wrap: wrap;
		justify-content: space-around;
	}
</style>

2.效果示例

在这里插入图片描述

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值