效果:
用到栅格布局、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>