uni-app頂部導(dǎo)航(可滑動(dòng))

版權(quán)聲明:本文為博主原創(chuàng)文章,遵循 CC 4.0 BY-SA 版權(quán)協(xié)議,轉(zhuǎn)載請(qǐng)附上原文出處鏈接和本聲明。

本文鏈接:https://blog.csdn.net/weixin_42560017/article/details/100356238

1.在app.vue中引入全局樣式:

<style>

/*每個(gè)頁面公共css */

@import './common/uni.css';

/*引入css3動(dòng)畫庫*/

@import './common/animate.css';

</style>

2.在項(xiàng)目根目錄components文件夾下新建一個(gè)vue文件

這里我命名為index.vue,文件內(nèi)容如下:

<template>

<view>

<!--頂部導(dǎo)航欄-->

<view class="uni-tab-bar">

<scroll-view scroll-x class="uni-swiper-tab">

<block v-for="(tabBar,index) in tabBars" :key="index">

<view class="swiper-tab-list" :class="{'active': tabIndex==index}" @tap="toggleTab(index)">

{{tabBar.name}}

<view class="swiper-tab-line">

</view>

</view>

</block>

</scroll-view>

</view>

<!--內(nèi)容區(qū)-->

<view class="uni-tab-bar">

<swiper :current="tabIndex" @change="tabChange">

<swiper-item v-for="(content,index) in contentList" :key="index" >

<view class="swiper-item">{{content}}</view>

</swiper-item>

</swiper>

</view>

</view>

</template>

<script>

export default {

data() {

return {

tabIndex: 0, //選中標(biāo)簽欄的序列

contentList: [

"關(guān)注",

"推薦",

"熱點(diǎn)",

"體育",

'財(cái)經(jīng)',

'娛樂',

],

tabBars:[

{

name: '關(guān)注',

id: 'guanzhu'

},

{

name: '推薦',

id: 'tuijian'

},

{

name: '熱點(diǎn)',

id: 'redian'

},

{

name: '體育',

id: 'tiyu'

},

{

name: '財(cái)經(jīng)',

id: 'caijing'

},

{

name: '娛樂',

id: 'yule'

}

],

swiperHeight: 0

}

},

components:{

},

onLoad() {

},

methods: {

toggleTab(index){

console.log(index)

this.tabIndex = index

},

//滑動(dòng)切換swiper

tabChange(e){

console.log(e.detail)

const tabIndex = e.detail.current

this.tabIndex = tabIndex

}

}

}

</script>

<style>

.swiper-tab-list{

color: #969696;

font-weight: bold;

}

.uni-tab-bar .active{

color: #343434;

}

.active .swiper-tab-line{

border-bottom: 6upx solid #FEDE33;

width: 70upx;

margin: auto;

border-top: 6upx solid #FEDE33;

border-radius: 20upx;

}

.uni-swiper-tab{

border-bottom: 1upx solid #eeeeee;

}

</style>

————————————————

版權(quán)聲明:本文為CSDN博主「weixin_42560017」的原創(chuàng)文章,遵循 CC 4.0 BY-SA 版權(quán)協(xié)議,轉(zhuǎn)載請(qǐng)附上原文出處鏈接及本聲明。

原文鏈接:https://blog.csdn.net/weixin_42560017/article/details/100356238

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容