添加顶部选项卡

<template>
    <view>
        <!-- 顶部选项卡 -->
        <scroll-view scroll-x style="width: 100%;white-space: nowrap;
        border-bottom: 1px solid red;height: 100rpx;"
        :scroll-into-view="scrollinto" scroll-with-animation>
            <view v-for="(item,index) in tabBars" :key="index"
            style="display: inline-block;padding:30rpx;" :id=" 'tab'+index"
            :class="tabIndex === index ? 'active' :' ' " @click="changeTab(index)">             {{item.name}} </view>                 
        </scroll-view>
        <swiper :duration="150" :current="tabIndex" @change="onChangeTab"         :style="'height:'+scrollH+'px;'">
            <swiper-item v-for="(item,index) in newslist" :key="index">
                <scroll-view scroll-y="true" :style=" 'height:'+scrollH+'px;' ">
                    <block v-for="(item2,index2) in item.list" :key="index2">
                        <!-- 列表样式 -->
                        <common-list :item="item2" :index="index2" @follow="follow" 
                        @doSupport="doSupport"></common-list>
                        <!-- 全局分割线 -->
                        <divider></divider>
                    </block>
                </scroll-view>
            </swiper-item>
        </swiper>
    </view>
</template>

<script>
    export default {
        data() {
            return {
                // 列表高度
                scrollH:600,
                // 顶部选项卡
                scrollinto:" ",     
                tabIndex:0,             
                tabBars: [{
                    name: '关注'
                },{
                    name: '推荐'
                },{
                    name: '体育'
                },{
                    name: '热点'
                },{
                    name: '财经'
                },{
                    name: '娱乐'
                },{
                    name: '军事'
                },{
                    name: '历史'
                }],
                newslist:[ ]    
            }
        },
        onLoad() {
            // 获取可视区域高度
                uni.getSystemInfo({
                    success: (res) => {
                        this.scrollH = res.windowHeight - uni.upx2px(102)
                    }
                })
                // 根据选项生成列表
                this.getData()
        },
        methods: {
            // 获取数据
            getData(){
                var arr = []
                    for (let i = 0; i < this.tabBars.length; i++) {
                        let obj ={
                            list:[{
                                username:"昵称",
                                userpic:"/static/touxiang.png",
                                newstime:"2019-10-20 下午04:30",
                                isFollow:false,
                                title:"我是标题",
                                titlepic:"",
                                support:{
                                     type:"support", //顶
                                    support_count:1,
                                    unsupport_count:2
                                },
                                comment_count:2,
                                share_count:2
                            },
                            {
                                username:"昵称",
                                userpic:"/static/touxiang.png",
                                newstime:"2019-10-20 下午04:30",
                                isFollow:false,
                                title:"我是标题",
                                titlepic:"/static/hua.png",
                                support:{
                                    type:"unsupport", //踩
                                    support_count:1,
                                    unsupport_count:2
                                },
                                comment_count:2,
                                share_count:2
                            },
                            {
                                username:"昵称",
                                userpic:"/static/touxiang.png",
                                newstime:"2019-10-20 下午04:30",
                                isFollow:false,
                                title:"我是标题",
                                titlepic:"/static/hua.png",
                                support:{
                                    type:"", //未操作
                                    support_count:1,
                                    unsupport_count:2
                                },
                                comment_count:2,
                                share_count:2
                            }]
                        }
                        arr.push(obj)
                    }
                    this.newslist = arr
            },
            // 监听滑动
            onChangeTab(e){
                this.changeTab(e.detail.current)
            },
            // 切换选项
            changeTab(index){
                if (this.tabIndex === index) {
                    return;
                }
                this.tabIndex = index
                this.scrollInto = 'tab'+index
            }
        }
    }

</script>

<style>
    .active{
        color: red;
    }
</style>
 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值