小程序 scroll-view实现横向滚动的2种方法


<template>
    <view class="content">
        <scroll-view scroll-x="true">
            <view class="tabs">
                <view class="item" v-for="(item,index) in list">{{item}}</view>
            </view>
        </scroll-view>
        
        <scroll-view scroll-x="true" class="tabs_container">
            <view class="tabs_item" v-for="(item,index) in list">{{item}}</view>
        </scroll-view>
    </view>
</template>
<script>
    export default {
        data() {
            return {
                title: 'Hello',
                list: []
            }
        },
        onLoad() {
            for (var i = 0; i < 9; i++) {
                this.list.push('tab' + i)
            }
        },
        methods: {

        }
    }
</script>
<style lang="scss" scoped>
    .tabs {
        display: flex;
        flex-wrap: nowrap;
        flex-direction: row;
        width: 100%;

        .item {
            width: 200rpx;
            height: 100rpx;
            line-height: 100rpx;
            background-color: red;
            text-align: center;
            margin-right: 20rpx;
            flex-shrink: 0;
        }
    }
    .tabs_container{
        margin-top: 30rpx;
        width: 100%;
        white-space: nowrap;
        text-align: right;
        .tabs_item{
            width: 200rpx;
            height: 100rpx;
            line-height: 100rpx;
            display: inline-block;
            background-color: red;
            text-align: center;
            margin-right: 20rpx;
        }
    }
</style>

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM