要點:
使用豎向滾動時,需要給 <scroll-view>
一個固定高度,通過 css 設置 height。
使用橫向滾動時,需要給 <scroll-view>
一個固定寬度,通過 css 設置 width。
<template> <view class="tab"> <scroll-view class="tab-scroll-view" :scroll-x="true"> <view class="tab-item" v-for="(item, index) in tabList" :key="index"> {{item.name}} </view> </scroll-view> </view> </template>
<style lang="less"> .tab-scroll-view { width: 750rpx; height: 84rpx; flex-direction: row; white-space: nowrap; .tab-item { display: inline-block; width: 150rpx; height: 284rpx; font-size: 16px; color: #555; border: 1px solid yellow; } } </style>