# 导航栏tab导航开发

修改page.json文件, 需要使用自定义组件
{
"path": "pages/news/news",
"style": {
"app-plus":{
"titleNView":false
}
}
},
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
在new.vue中增加
<template>
<view>
<!-- 自定义导航栏 -->
<uni-nav-bar :statusBar="true" @clickRight="openAdd">
<!-- 左边 -->
<block slot="left">
<view class="nav-left">
<view class="icon iconfont icon-qiandao"></view>
</view>
</block>
<!-- 中间 -->
<view class="nav-tab-bar u-f-ajc">
<block v-for="(tab, index) in tabBars" :key="tab.id">
<view class="u-f-ajc" :class="{'active': tabIndex===index}" @tap="changeTab(index)">{{tab.name}}
<view v-if="(tabIndex===index)" class="nav-tab-bar-line"></view>
</view>
</block>
</view>
<!-- 右边 -->
<block slot="right">
<view class="nav-right u-f-ajc">
<view class="icon iconfont icon-bianji1"></view>
</view>
</block>
</uni-nav-bar>
</view>
</template>
<script>
import uniNavBar from '../../components/uni-nav-bar/uni-nav-bar.vue'
export default {
components: {
uniNavBar
},
data() {
return {
tabIndex: 0,
tabBars: [{
name: '关注',
id: 'guanzhu'
},
{
name: '话题',
id: 'topic'
}
]
}
},
methods: {
// tab切换
changeTab(index) {
this.tabIndex = index
},
// 路由跳转
openAdd() {
uni.navigateTo({
url: '../add-input/add-input'
})
}
}
}
</script>
<style lang="less" scoped>
.nav-left>view,
.nav-right>view {
font-size: 40rpx;
}
.nav-left {
margin-left: 16rpx;
view {
color: #ff9619;
}
}
.nav-right {
width: 100%;
margin-left: 40rpx;
}
.nav-tab-bar {
width: 100%;
margin-left: -20rpx;
position: relative;
view {
font-size: 35rpx;
padding: 0 15rpx;
font-weight: bold;
color: #969696;
.nav-tab-bar-line {
border-bottom: 5rpx solid #fede33;
border-top: 5rpx solid #fede33;
width: 50rpx;
border-radius: 20rpx;
position: absolute;
bottom: 1rpx;
}
}
}
.active {
color: #333 !important;
}
</style>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
← 修复自定义组件 公共列表样式开发(上) →