效果图:
wxml:布局的话就是scroll-view这个组件
官方文档:https://developers.weixin.qq.com/miniprogram/dev/component/scroll-view.html
<!-- IQOO分类布局 -->
<!--------------- 侧方导航栏布局 ---------------->
<view class="container">
<scroll-view class='nav_left' scroll-y='true'>
<block wx:for="{{cateItems}}" wx:key="{{index}}">
<view class="nav_left_items {{curNav==item.cate_id?'active':''}}" bindtap="switchRightTab" data-index='{{index}}' data-id="{{item.cate_id}}">{{item.cate_name}}</view>
</block>
</scroll-view>
<scroll-view class="nav_right" scroll-y="true">
<!--如果有数据,才遍历项-->
<view wx:if="{{cateItems[curIndex].children.length>0}}">
<block wx:for="{{cateItems[curIndex].children}}" wx:key="{{index}}" >
<view class="nav_right_items" data-index='{{index}}' bindtap="iqoo">
<image src="{{item.image}}"></image>
<view class='name1'>{{item.name1}}</view>
<view class="name2">{{item.name2}}</view>
<view class="name3">{{item.name3}}</view>
</view>
</block>
</view>
<!--如果无数据,则显示数据-->
<view class="nocate" wx:else>
<text>该分类暂无数据</text>
</view>
</scroll-view>
</view>
js:数据是自己写好的 如果到家想通过后台获取的话就是在data中定义 ,然后去后台获取,我前边的博客中有类似向后台获取数据,请参考
Page({
/**
* 页面的初始数据
*/
data: {
cateItems: [
{
cate_id: 1,
cate_name: 'iQOO',
children: [
{
child_id: 1,
name1: 'iQOO Pro 5G版',
name2: '海风青 超广角后置AI三摄',
name3: '¥2399.00',
image: "https://shopstatic.vivo.com.cn/vivoshop/commodity/99/10001399_1566458712423_750x750.png"
},
{
child_id: 2,
name1: 'X30 Pro 5G版',
name2: '海风青 超广角后置AI三摄',
name3: '¥4399.00',
image: "https://shopstatic.vivo.com.cn/vivoshop/commodity/14/10001814_1576461527559_750x750.png"
},
{
child_id: 2,
name1: 'X30 Pro 5G版',
name2: '海风青 超广角后置AI三摄',
name3: '¥4399.00',
image: "https://shopstatic.vivo.com.cn/vivoshop/commodity/14/10001814_1576461527559_750x750.png"
},
{
child_id: 2,
name1: 'X30 Pro 5G版',
name2: '海风青 超广角后置AI三摄',
name3: '¥4399.00',
image: "https://shopstatic.vivo.com.cn/vivoshop/commodity/14/10001814_1576461527559_750x750.png"
},
{
child_id: 2,
name1: 'X30 Pro 5G版',
name2: '海风青 超广角后置AI三摄',
name3: '¥4399.00',
image: "https://shopstatic.vivo.com.cn/vivoshop/commodity/14/10001814_1576461527559_750x750.png"
},
{
child_id: 2,
name1: 'X30 Pro 5G版',
name2: '海风青 超广角后置AI三摄',
name3: '¥4399.00',
image: "https://shopstatic.vivo.com.cn/vivoshop/commodity/14/10001814_1576461527559_750x750.png"
},
{
child_id: 2,
name1: 'X30 Pro 5G版',
name2: '海风青 超广角后置AI三摄',
name3: '¥4399.00',
image: "https://shopstatic.vivo.com.cn/vivoshop/commodity/14/10001814_1576461527559_750x750.png"
},
{
child_id: 2,
name1: 'X30 Pro 5G版',
name2: '海风青 超广角后置AI三摄',
name3: '¥4399.00',
image: "https://shopstatic.vivo.com.cn/vivoshop/commodity/14/10001814_1576461527559_750x750.png"
},
{
child_id: 2,
name1: 'X30 Pro 5G版',
name2: '海风青 超广角后置AI三摄',
name3: '¥4399.00',
image: "https://shopstatic.vivo.com.cn/vivoshop/commodity/14/10001814_1576461527559_750x750.png"
},
]
},
{
cate_id: 2,
cate_name: ' NEX',
children: [
{
child_id: 1,
name1: 'X30 Pro 5G版',
name2: '海风青 超广角后置AI三摄',
name3: '¥4399.00',
image: "https://shopstatic.vivo.com.cn/vivoshop/commodity/14/10001814_1576461527559_750x750.png"
},
{
child_id: 2,
name1: 'X30 Pro 5G版',
name2: '海风青 超广角后置AI三摄',
name3: '¥4399.00',
image: "https://shopstatic.vivo.com.cn/vivoshop/commodity/14/10001814_1576461527559_750x750.png"
},
]
},
{
cate_id: 3,
cate_name: 'X系列'
},
{
cate_id: 4,
cate_name: 'S系列'
},
{
cate_id: 5,
cate_name: 'Z系列'
},
{
cate_id: 6,
cate_name: 'U系列'
},
{
cate_id: 7,
cate_name: 'Y系列'
},
{
cate_id: 8,
cate_name: '充电'
},
{
cate_id: 9,
cate_name: '音乐'
},
{
cate_id: 10,
cate_name: '配件'
},
{
cate_id: 11,
cate_name: '智能'
},
{
cate_id: 12,
cate_name: '摄影'
},
{
cate_id: 13,
cate_name: '生活'
}
],
curNav: 1,
curIndex: 0
},
//左侧导航栏索引
switchRightTab: function (e) {
let id = e.target.dataset.id, index = e.target.dataset.index;
this.setData({
curNav: id,
curIndex: index
})
},
})
wxss:
/* pages/iqoo/iqoo.wxss */
/* IQOO分类样式 */
/****************** 侧方导航栏 *******************/
.container{
position:fixed;
width:100%;
height:100%;
background-color:#FFF;
}
.nav_left{
width:25%;
height:100%;
background:#F2F2F2;
text-align:center;
position:absolute;
top:0;
left:0;
}
.nav_left .nav_left_items{
height:100rpx;
line-height:100rpx;
font-size:28rpx;
}
.nav_left .nav_left_items.active{
position:relative;
/* background:#FFF; */
color:#3366cc;
}
.nav_left .nav_left_items.active::before{
display: inline-block;
width:6rpx;
height:60rpx;
background:#3366cc;
content:'';
position:absolute;
top:20rpx;
left:0;
}
/****************** 右方数据栏 *******************/
.nav_right{
position:absolute;
top:0;
right:0;
width:75%;
height:100%;
}
.nav_right .nav_right_items{
float: left;
width: 50%;
text-align: center;
padding:30rpx 0;
}
.nav_right .nav_right_items image{
width: 180rpx;
height: 180rpx;
}
.name1{
margin-top: 30rpx;
font-weight: bold;
font-size: 25rpx;
text-align: center;
}
.name2{
margin-top: 20rpx;
font-size: 20rpx;
}
.name3{
margin-top: 20rpx;
font-size: 25rpx;
text-align: center;
color: #cc3333;
font-weight: bold;
}
.nocate{
padding:100rpx;
text-align: center;
}
.nocate image{
width:70rpx;
height:70rpx;
}
.nocate text{
font-size:28rpx;
display:block;
color:#BBB;
}
/*隐藏滚动条*/
::-webkit-scrollbar{
width: 0;
height: 0;
color: transparent;
}