在小程序中写一个横向视图,直接用一个scroll-view,加上scroll-x="true"属性就OK了
xml
<scroll-view class="wrap" scroll-x="true"><block wx:for="{{[1,2,3,4,5]}}" wx:key="item" wx:for-item="item"><view class="item"><text>{{item}}</text></view></block>
</scroll-view>
css
.item{width:300px;text-align:center;line-height: 40px;}
对于scroll-view横向滑动,文档中并没有多余的提示,但是上面的写法 并没有达到我要的的横向滑动效果啊 emmmmm,上网搜了一下才知道 scroll-view横向滑动还需要给scroll-view添加2句css white-space: nowrap;
display: inline-block;
这样就可以了
完整css
.wrap {white-space: nowrap;display: inline-block;
}.item{width:300px;text-align:center;line-height: 40px;}