uniapp實(shí)現(xiàn)tabs切換(可滑動(dòng))效果實(shí)例
uniapp實(shí)現(xiàn)tabs切換(可滑動(dòng))
<template> <view class="body-view"> <!-- 使用scroll-view實(shí)現(xiàn)tabs滑動(dòng)切換 --> <scroll-view class="top-menu-view" scroll-x="true" :scroll-into-view="tabCurrent"> <view class="menu-topic-view" v-for="item in tabs" :id="'tabNum'+item.id" :key="(item.id - 1)" @click="swichMenu(item.id - 1)"> <view :class="currentTab==(item.id - 1) ? 'menu-topic-act' : 'menu-topic'"> <text class="menu-topic-text">{{item.name}}</text> <view class="menu-topic-bottom"> <view class="menu-topic-bottom-color"></view> </view> </view> </view> </scroll-view> <!-- 內(nèi)容 --> <swiper class="swiper-box-list" :current="currentTab" @change="swiperChange"> <swiper-item class="swiper-topic-list" v-for="item in swiperDateList" :key="item.id"> <view class="swiper-item"> {{item.content}} </view> </swiper-item> </swiper> </view> </template> <script> export default { data() { return { tabs: [{ id: 1, name: '推薦' }, { id: 2, name: '交通交通' }, { id: 3, name: '住房' }, { id: 4, name: '社會(huì)保障' }, { id: 5, name: '民生熱點(diǎn)' }, { id: 6, name: '即日頭條' }, { id: 7, name: '新聞聯(lián)播' }, ], currentTab: 0, tabCurrent: 'tabNum1', // Tab切換內(nèi)容 swiperDateList: [{ id: 1, content: '推薦' }, { id: 2, content: '交通交通' }, { id: 3, content: '住房' }, { id: 4, content: '社會(huì)保障' }, { id: 5, content: '民生熱點(diǎn)' }, { id: 6, content: '即日頭條' }, { id: 7, content: '新聞聯(lián)播' }, ], } }, onLoad() { }, methods: { swichMenu(id) { this.currentTab = id console.log(11,id) this.tabCurrent = 'tabNum'+ id }, swiperChange(e) { console.log(22,e.detail.current) let index = e.detail.current this.swichMenu(index) } } } </script> <style scoped lang="scss"> .body-view { height: 100vh; width: 100%; display: flex; flex: 1; flex-direction: column; overflow: hidden; align-items: flex-start; justify-content: center; } .top-menu-view { display: flex; position: fixed; top: 100rpx; left: 0; white-space: nowrap; width: 100%; background-color: #FFFFFF; height: 86rpx; line-height: 86rpx; border-top: 1rpx solid #d8dbe6; .menu-topic-view { display: inline-block; white-space: nowrap; height: 86rpx; position: relative; .menu-topic-text { font-size: 30rpx; color: #303133; padding: 10rpx 40rpx; } // .menu-topic-act { // margin-left: 30upx; // margin-right: 10upx; // position: relative; // height: 100%; // display: flex; // align-items: center; // justify-content: center; // } .menu-topic-bottom { position: absolute; bottom: 0; width: 100%; .menu-topic-bottom-color { width: 40rpx; height: 4rpx; } } .menu-topic-act .menu-topic-bottom { display: flex; justify-content: center; } .menu-topic-act .menu-topic-bottom-color { background: #3d7eff; } } } .swiper-box-list { width: 100%; padding-top: 200rpx; flex:1; background-color: #FFFFFF; .swiper-topic-list { width: 100%; } } </style>
繼續(xù)加油呀~
到此這篇關(guān)于uniapp實(shí)現(xiàn)tabs切換(可滑動(dòng))效果的文章就介紹到這了,更多相關(guān)uniapp實(shí)現(xiàn)tabs切換內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
- 在uniapp中實(shí)現(xiàn)中英文切換的方法
- uniapp?動(dòng)態(tài)組件實(shí)現(xiàn)Tabs標(biāo)簽切換組件(喜馬拉雅app作為案例)
- vue、uniapp實(shí)現(xiàn)組件動(dòng)態(tài)切換效果
- uniapp單頁面實(shí)現(xiàn)頁面切換的使用示例
- uniapp實(shí)現(xiàn)全局設(shè)置字體大小(小中大的字體切換)
- uniapp組件之tab選項(xiàng)卡滑動(dòng)切換功能實(shí)現(xiàn)
- Uniapp 實(shí)現(xiàn)頂部標(biāo)簽頁切換功能(詳細(xì)步驟)
相關(guān)文章
在瀏覽器中獲取當(dāng)前執(zhí)行的腳本文件名的代碼
同事提了一個(gè)問題,如何在瀏覽器中動(dòng)態(tài)插入的 JavaScript 文件中,獲取當(dāng)前文件名?2011-07-07淺析JavaScript中的同名標(biāo)識(shí)符優(yōu)先級(jí)
這篇文章主要介紹了JavaScript中的同名標(biāo)識(shí)符優(yōu)先級(jí)。需要的朋友可以過來參考下,希望對(duì)大家有所幫助2013-12-12javascript實(shí)現(xiàn)計(jì)算器功能
這篇文章主要為大家詳細(xì)介紹了javascript實(shí)現(xiàn)計(jì)算器功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-03-03Javascript與vbscript數(shù)據(jù)共享
Javascript與vbscript數(shù)據(jù)共享...2007-01-01layui清空,重置表單數(shù)據(jù)的實(shí)例
今天小編就為大家分享一篇layui清空,重置表單數(shù)據(jù)的實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2019-09-09JS中JSON.stringify使用場(chǎng)景面試精講
這篇文章主要為大家介紹了JS中JSON.stringify使用場(chǎng)景面試精講,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-10-10javascript實(shí)現(xiàn)時(shí)鐘動(dòng)畫
這篇文章主要為大家詳細(xì)介紹了javascript實(shí)現(xiàn)時(shí)鐘動(dòng)畫,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-12-12