uni-app页面点击tab左右滑动(swiper)

uni-app基于<swiper>和uViews的<u-tabs>实现点击标签切换和页面左右滑动联动

<template>
    <view>
        <u-tabs :list="list" lineWidth="40" :current="current" @change="tabChange"></u-tabs>
        <swiper class="scroll-view-height" @change="swipeIndex"
                :current="current" :duration="300">
            <swiper-item>
                <scroll-view scroll-y="true" class="scroll-view-height list-content">
                    <view class="list-item" v-for="(item,index) in 20"
                          :key="'A'+index">tab1- {{index}}</view>
                </scroll-view>
            </swiper-item>
            <swiper-item>
                <scroll-view scroll-y="true" class="scroll-view-height list-content">
                    <view class="list-item" v-for="(item,index) in 20"
                          :key="'B'+index">tab2- {{index}}</view>
                </scroll-view>
            </swiper-item>
        </swiper>
        <tabbar :current="2"></tabbar>
    </view>
</template>

<script>
    export default {
        name: "index",
        data() {
            return {
                // swiper索引
                current: 0,
                list: [
                    {
                        name: 'tab1',

                    },
                    {
                        name: 'tab2',

                    },

                ],

            }
        },
        methods: {
            swipeIndex(index) {
                // 获得swiper切换后的current索引
                this.current =index.detail.current
            },
            swtichSwiper(index) {
                // 通过tab组件回调点击切换的index同步swiper的current索引
                this.current = index
            },
            tabChange(data) {
                this.current = data.index
            },

        }

    }
</script>

<style scoped lang="scss">
    .scroll-view-height {
        /* 页面高度减去包含状态栏、标题、tab组件的高度 */
        height: calc(100vh - var(--status-bar-height) - 178rpx);
    }

    .list-content {
        background-color: #F4F4F4;
    }

    .list-item {
        height: 100rpx;
        line-height: 100rpx;
        text-align: center;
        margin: 4rpx 0;
        background-color: #FFFFFF;
    }

</style>

  • 1
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Uni-app 是一款基于 Vue.js 的跨平台应用开发框架,它可以用于同时开发多个平台的应用程序,包括 iOS、Android、H5 等。Swiper 是一款流行的移动端轮播图插件,用于实现图片轮播、滑动切换等效果。在 Uni-app 中,你可以使用 Swiper 插件来创建轮播图组件。 要在 Uni-app 中使用 Swiper,首先需要在项目中安装 Swiper 插件。可以通过 npm 命令来进行安装: ``` npm install uni-swiper ``` 安装完成后,在需要使用 Swiper页面中引入组件: ```vue <template> <view> <swiper :indicator-dots="true" :autoplay="true" :interval="3000"> <swiper-item v-for="(item, index) in swiperList" :key="index"> <image :src="item.imageUrl"></image> </swiper-item> </swiper> </view> </template> <script> import uniSwiper from 'uni-swiper'; export default { components: { uniSwiper, uniSwiperItem: uniSwiper.Item, }, data() { return { swiperList: [ { imageUrl: 'https://example.com/image1.jpg' }, { imageUrl: 'https://example.com/image2.jpg' }, { imageUrl: 'https://example.com/image3.jpg' }, ], }; }, }; </script> ``` 上面的代码演示了一个简单的轮播图组件,通过 `swiper` 和 `swiper-item` 标签来包裹轮播项。`swiper` 组件上的 `indicator-dots` 属性用于显示底部指示点,`autoplay` 属性用于自动播放,`interval` 属性用于设置切换间隔时间。在 `swiper-item` 中,使用 `v-for` 指令来遍历 `swiperList` 数组生成轮播项。 以上是一个简单的 Uni-app 中使用 Swiper 的例子,你可以根据自己的需求进行定制和扩展。希望对你有帮助!如需更多详细信息,请参考 Uni-appSwiper 的官方文档。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值