①uniapp写首页

效果:

用到栅格布局、u-col的for循环、轮播图、tabs

直接复制粘贴到vue文件里面就可以显示出这个效果了,不需要写其他的

index.vue:

<template>
	<view>
		<u-swiper :list="imglist"></u-swiper>
		<u-tabs class="u-m-t-20" :list="sortlist" :is-scroll="false" :current="currentSort" @change="changeSort"
			bar-width="80" item-width="160"> </u-tabs>
		<view>
			<!-- gutter为内部两个组件的间距 -->
			<u-row gutter="16">
				<!-- 通过col组件的span设置需要分栏的比例,还可以循环牛批 -->
				<u-col span="6" v-for="i in 12">
					<!-- 写navigator里面是因为点击图片要能跳转 -->
					<navigator class="goods-item">
						<!-- 宽度设置为百分百,因为是栅格布局,所以宽度刚好 -->
						<u-image width="100%" height="400rpx"
							src="https://img.alicdn.com/imgextra/i3/29757030/O1CN01COfITQ21nn4hVCwCk_!!0-saturn_solar.jpg_468x468q75.jpg_.webp">
						</u-image>
						<view class="title">羊毛大衣</view>
						<view class="u-flex u-row-between">
							<view class="price">¥ 99</view>
							<view class="sales">销量:76</view>
						</view>
					</navigator>
				</u-col>
				<u-col span="6">
					<view class="demo-layout bg-purple-light">栅格</view>
				</u-col>
			</u-row>
		</view>

	</view>
</template>
<script>
	export default {
		data() {
			return {
				imglist: [
					'https://t10.baidu.com/it/u=2912690280,2792728341&fm=173&app=25&f=JPEG?w=640&h=394&s=7A902EC5400233575A35C12703007042',
					'https://t11.baidu.com/it/u=2429171512,2295101553&fm=173&app=25&f=JPEG?w=640&h=402&s=7B782AD7364B55490CF4727203007076'
				],
				sortlist: [{
						name: '默认'
					},
					{
						name: '销量'
					},
					{
						name: '推荐'
					},
					{
						name: '最新'
					},
				],
				currentSort: 0, // 设置tabs一开始选中第0个
			}
		},

		async onLoad() {

			// 测试登录的API
			const data = {
				email: "test@a.com",
				password: "123123"
			}
			const res = await this.$u.api.authLogin(data) //把data传给params,返回的是token。就跟postman传过去的东西和返回的东西一样
			console.log(res);
		},
		methods: {
			changeSort(index) { //index是当前的索引
				this.currentSort = index;
				console.log(index);
			}
		}
	}
</script>

<style lang="scss" scoped>
	.goods-item {
		padding: 20rpx;
		margin-top: 30rpx;
		box-shadow: 0 12rpx 20rpx 0 rgba(0, 0, 0, .1);        //给栅格的格子写样式

		.title {
			margin-top: 10rpx;
			font-weight: 500;
			font-size: 32rpx;
		}

		.price {
			color: red
		}

		.sales {
			color: #888
		}
	}
</style>

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值