uniapp并不提供竖向tab组件,需要我们自定义组件。
1.项目结构图

2.items/index.vue
<template>
<view>
<view class="scroll-view-container">
<!-- 左侧滑动区域 -->
<scroll-view scroll-y="true" class="left-scroll-view" :style="{height: wh + 'px'}">
<block v-for="(c,i) in catalogList" :key="c.id">
<view :class="['left-scroll-view-item',c.id === active ? 'active' : '']"
@click="activeChanged(c.id)">
{{c.cname}}
</view>
</block>
</scroll-view>
<!-- 右侧滑动区域 -->
<scroll-view scroll-y="true" :style="{height: wh + 'px'}">
<view>
<!-- 右侧静态数据 -->
<view class="courseCateList" v-for="(c,index) in courseList" :key="c.cid">
<view class="courseCateList-div">
<image :src="c.logo"></image>
</view>
</view>
</view>
</scroll-view>
</view>
</view>
</template>
<script>
export default {
data() {
return {
wh: 0, //当前设备可用高度
catalogList: [{
"cid": 1,
"id": "woman",
"cname": "女装"
},
{
"cid": 2,
"id": "man",
"cname": "男装"
},
{
"cid": 3,
"id": "makeup",
"cname": "美妆"
},
{
"cid": 4,
"id": "mobile",
"cname": "手机"
},
{
"cid": 5,
"id": "food",
"cname": "零食"
},
{
"cid": 6,
"id": "appliances",
"cname": "家电"
},
{
"cid": 7,
"id": "auto",
"cname": "汽车"
},
{
"cid": 8,
"id": "book",
"cname": "图书"
},
{
"cid": 9,
"id": "fresh",
"cname": "生鲜"
},
{
"cid": 10,
"id": "furniture",
"cname": "家具"
},
{
"cid": 11,
"id": "baby",
"cname": "母婴"
},
{
"cid": 12,
"id": "drugs",
"cname": "医药"
},
{
"cid": 13,
"id": "tea",
"cname": "茶酒"
},
{
"cid": 14,
"id": "pet",
"cname": "宠物"
}
], //左侧板块数据
courseList: [{
"cid": 1,
"logo": "/static/items/items_001.jpg"
},
{
"cid": 5,
"logo": "/static/items/items_001.jpg"
},
{
"cid": 7,
"logo": "/static/items/items_001.jpg"
},
{
"cid": 10,
"logo": "/static/items/items_001.jpg"
},
{
"cid": 31,
"logo": "/static/items/items_001.jpg"
},
{
"cid": 11,
"logo": "/static/items/items_001.jpg"
},
{
"cid": 12,
"logo": "/static/items/items_001.jpg"
},
{
"cid": 13,
"logo": "/static/items/items_001.jpg"
},
{
"cid": 32,
"logo": "/static/items/items_001.jpg"
}
], //右侧内容数组
active: 'c' //默认激活项
};
},
// 页面加载调用
onLoad() {
const sysInfo = uni.getSystemInfoSync(); //当前设备的数据
console.log(sysInfo);
this.wh = sysInfo.windowHeight;
},
methods: {
//点击改变默认激活项、重新刷新右侧内容
activeChanged(catalogId) {
console.log(catalogId);
this.active = catalogId;
}
}
}
</script>
<style lang="scss">
.scroll-view-container {
display: flex;
.left-scroll-view {
width: 160px;
.left-scroll-view-item {
background-color: #f1f1f1;
line-height: 60px;
text-align: center;
font-size: 12px;
// 如,元,既,包,上,又,下,设,特,样
&.active {
background-color: #ffffff;
position: relative;
color: #00aaff;
//前,设,伪
&::before {
content: ' ';
display: block;
width: 3px;
height: 40px;
background-color: #1296db;
position: absolute;
top: 50%;
left: 0;
//撤,my,50%
transform: translateY(-50%);
}
}
}
}
}
.courseCateList {
width: 13rem;
height: 8rem;
background-color: #eeeeee;
margin: 1rem auto;
.courseCateList-div {
image {
width: 13rem;
height: 8rem;
line-height: 10rem;
border-radius: 10px;
}
}
}
</style>
运行效果:
