AppTabbar.vue
2.05 KB
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
<template>
<view class="app-tabbar">
<nut-tabbar
:model-value="activeTab"
bottom
placeholder
safe-area-inset-bottom
:active-color="activeColor"
:unactive-color="inactiveColor"
@tab-switch="handleTabSwitch"
>
<nut-tabbar-item
v-for="item in tabItems"
:key="item.name"
:name="item.name"
:tab-title="item.title"
>
<template #icon="{ active }">
<component
:is="item.icon"
size="18"
:color="active ? activeColor : inactiveColor"
/>
</template>
</nut-tabbar-item>
</nut-tabbar>
</view>
</template>
<script setup>
import { computed } from 'vue'
import Taro from '@tarojs/taro'
import { Home, Message, My } from '@nutui/icons-vue-taro'
const props = defineProps({
current: {
type: String,
required: true,
},
})
const activeColor = '#a67939'
const inactiveColor = '#8b95a7'
const tabItems = [
{
name: 'home',
title: '首页',
icon: Home,
url: '/pages/index/index',
},
{
name: 'message',
title: '消息',
icon: Message,
url: '/pages/message/index',
},
{
name: 'mine',
title: '我的',
icon: My,
url: '/pages/mine/index',
},
]
const activeTab = computed(() => props.current)
const handleTabSwitch = (...args) => {
const nextTab = args[1]
const target = tabItems.find((item) => item.name === nextTab)
if (!target || target.name === props.current) {
return
}
Taro.redirectTo({
url: target.url,
})
}
</script>
<style lang="less">
.app-tabbar {
:deep(.nut-tabbar) {
left: 24rpx;
right: 24rpx;
bottom: 24rpx;
width: auto;
border: 2rpx solid rgba(166, 121, 57, 0.12);
border-radius: 999rpx;
background: rgba(255, 255, 255, 0.96);
box-shadow: 0 24rpx 60rpx rgba(15, 23, 42, 0.12);
overflow: hidden;
}
:deep(.nut-tabbar-item_icon-box) {
padding-top: 8rpx;
}
:deep(.nut-tabbar-item_icon-box_nav-word) {
margin-top: 8rpx;
font-size: 22rpx;
font-weight: 600;
}
}
</style>