uniapp tab切换并发送请求

<template>
	<view class="list-content">
		<view class="tabs">
			<view v-for="(item, index) in TabList" :key="index" class="tab-item"
				:class="{ current: tabCurrentIndex === index }" @click="tabClick(index)">
				{{ item.name }}
			</view>
		</view>
		<view class="list-item" v-for="(item,index) in TabList" :key="index" v-if="tabCurrentIndex === index">
			<view class="item" v-for="(item,index) in itemList" :key="index">
				<image :src="item.mainPic" mode="widthFix"></image>
				<view class="content">
					<view class="title">
						{{item.title}}
					</view>
					<view class="data">
						<view class="price">{{item.actualPrice}}</view>
						<view class="coupons">券{{item.couponPrice}}元</view>
					</view>
					<view class="bottom">
						<text class="yj">原价:{{item.originalPrice}}</text>
						<text class="sold">已售:{{item.monthSales}}件</text>
					</view>
					<text class="btn">领券购买</text>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				itemList: [],
				pageSize: 20,
				pageId: 1,
				TabList: [{
						id: '',
						name: '推荐'
					},
					{

						id: '1',
						name: '女装'
					},
					{
						id: '2',
						name: '母婴'
					},
					{
						id: '3',
						name: '美妆'
					},
					{
						id: '4',
						name: '居家日用'
					},
					{
						id: '5',
						name: '鞋品'
					},
					{
						id: '6',
						name: '美食'
					},
					{
						id: '7',
						name: '文娱车品'
					},
					{
						id: '8',
						name: '数码家电'
					},
					{
						id: '9',
						name: '男装'
					},
					{
						id: '10',
						name: '内衣'
					},
					{
						id: '11',
						name: '箱包'
					},
					{
						id: '12',
						name: '配饰'
					},
					{
						id: '13',
						name: '户外运动'
					},
					{
						id: '14',
						name: '家装家纺'
					}
				],
				tabCurrentIndex: 0,
			}
		},
		onLoad() {
			this.getList();
		},
		methods: {
			changeTab(e) {
				this.tabCurrentIndex = e.target.current;

			},
			//顶部tab点击
			tabClick(index) {
				this.tabCurrentIndex = index;
				this.itemList = []
				this.getList(this.TabList[index].id)
			},

			getList(id) {
				uni.showLoading({
					title: '加载中',
					mask: true
				});
				uni.request({
					url: '',
					method: 'GET',
					data: {
						cids: id,
						pageSize: this.pageSize,
						pageId: this.pageId
					},
					header: {
						'content-type': 'application/json'
					},
					success: res => {
						this.itemList = res.data.data.data.list;
						setTimeout(function() {
							uni.hideLoading();
						}, 100);
					},
				});
			}
		}
	}
</script>

<style lang="scss">
// tab切换
	.tabs {
		position: relative;
		margin-top: 20rpx;
		margin-left: 20rpx;
		background: #ffff;
		z-index: 9;
		padding: 0 15px;
		text-align: center;
		height: 88rpx;
		line-height: 88rpx;
		display: flex;
		flex-flow: row;
		justify-content: space-between;
		color: #fff;
		font-size: 16px;
		overflow-x: auto;
		white-space: nowrap;
		overflow-y: hidden;
	}

	.tab-item {
		margin-right: 15px;
		color: #999999;
		font-size: 32rpx;
	}

	.tab-item.current {
		color: #ff0036;
		border-bottom: 4rpx solid #ff0036;
		font-size: 32rpx;
		font-weight: bold;
	}

	::-webkit-scrollbar {
		display: none;
		width: 0;
		height: 0;
		color: transparent;
	}


	/*商品列表*/
	.list-item {
		position: relative;
		padding: 20rpx;
	}

	.list-item .item {
		background-color: #ffffff;
		width: 47%;
		margin-bottom: 20rpx;
		margin-right: 20rpx;
		float: left;
		padding: 10rpx;
		border-radius: 6rpx;
		box-shadow: 0px 4px 8px #eeeeee;
		overflow: hidden;
	}

	.list-item .item:nth-of-type(2n) {
		margin-right: auto;
	}

	.list-item .item image {
		width: 100%;
		height: 340rpx;
		border-radius: 6rpx;
	}

	.list-item .item .content .title {
		font-size: 26rpx;
		line-height: 1.6;
		font-weight: 600;
		color: #333;
		text-overflow: -o-ellipsis-lastline;
		overflow: hidden;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-line-clamp: 2;
		-webkit-box-orient: vertical;
	}

	.list-item .item .content .title .icon {
		position: relative;
		top: 10rpx;
		width: 38rpx;
		height: 38rpx;
	}

	.list-item .item .content .data {
		padding: 6rpx 0;
		display: flex;
		align-items: center;
		justify-content: space-between;
	}

	.list-item .item .content .data .price {
		color: #ea3724;
		font-size: 28rpx;
		font-weight: 600;
	}

	.list-item .item .content .coupons {
		position: relative;
		background-color: #f95008;
		color: #fff;
		font-size: 22rpx;
		border-radius: 4rpx;
		padding: 0 10rpx;
		width: auto;
		display: inline-block;
	}

	.list-item .item .content .bottom {
		position: relative;
		padding: 6rpx 0;
		border-top: 1px solid #eee;
		display: flex;
		align-items: center;
		justify-content: space-between;
	}

	.list-item .item .content .bottom .yj {
		color: #666666;
		font-size: 22rpx;
		font-weight: 500;
		width: auto;
		display: inline-block;
		text-decoration: line-through;
	}

	.list-item .item .content .bottom .sold {
		color: #666666;
		font-size: 22rpx;
		font-weight: 500;
		width: auto;
		display: inline-block;
	}

	.list-item .item .content .btn {
		background-color: #f95008;
		color: #fff;
		width: auto;
		display: block;
		text-align: center;
		border-radius: 10rpx;
		padding: 6rpx;
	}
</style>

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值