最大盒子要100%高度,scroll-view的寬度不能設置固定寬度;
<scroll-view class="bottomBox" scroll-x="true" @scroll="scroll">
<view @click="go(i)" class="commodity" v-for="(item,i) in list" :key="i">
{{item.title}}
</view>
</scroll-view>
list: [{
id: 1,
title: "111"
}, {
id: 2,
title: "2222"
}, {
id: 3,
title: "3333"
}, {
id: 4,
title: "3333"
},
{
id: 5,
title: "3333"
},
],
此外無論是組件還是寫在一個頁面內 最大的盒子記得加上height:100%;
.bottomBox {
width: 100%; // 一定不能給固定寬度,會失效
height: 100%;
background-color: aqua;
white-space: nowrap; //這個屬性一定要添加
padding: 20upx;
.commodity {
display: inline-block;//這個也是一定要添加的
width: 196upx;
height: 360upx;
margin-right: 11upx;
background-color: pink;
}
}