Commit 2936e8a4 authored by liubinyu's avatar liubinyu

tabbar激活

parent d2b39a3a
<template> <template>
<view class="tabbar"> <view class="tabbar">
<view class="item" @click="go('/pages/home/home')"> <view class="item" :class="{ active: page.indexOf('home') > -1 }" @click="go('/pages/home/home')">
<image class="icon" src="@/static/icon-home.png" mode="aspectFit"></image> <image class="icon" src="@/static/icon-home.png" mode="aspectFit"></image>
<view class="name">{{ $t('Home') }}</view> <view class="name">{{ $t('Home') }}</view>
</view> </view>
<view class="item" @click="go('/pages/chat/chat')"> <view class="item" :class="{ active: page.indexOf('chat') > -1 }" @click="go('/pages/chat/chat')">
<image class="icon" src="@/static/icon-chat.png" mode="aspectFit"></image> <image class="icon" src="@/static/icon-chat.png" mode="aspectFit"></image>
<view class="name">{{ $t('Astrologer') }}</view> <view class="name">{{ $t('Astrologer') }}</view>
</view> </view>
<view class="item" @click="go('/pages/user/user')"> <view class="item" :class="{ active: page.indexOf('user') > -1 }" @click="go('/pages/user/user')">
<image class="icon" src="@/static/icon-user.png" mode="aspectFit"></image> <image class="icon" src="@/static/icon-user.png" mode="aspectFit"></image>
<view class="name">{{ $t('Profile') }}</view> <view class="name">{{ $t('Profile') }}</view>
</view> </view>
...@@ -19,16 +19,21 @@ ...@@ -19,16 +19,21 @@
export default { export default {
name: "tabbar", name: "tabbar",
data() { data() {
return {}; return {
page: '', // 当前页面路径
active: '', // 激活按钮
};
}, },
beforeCreate() { beforeCreate() {
uni.hideTabBar(); uni.hideTabBar();
}, },
created() {
const pages = getCurrentPages();
this.page = pages[pages.length - 1].route;
},
methods: { methods: {
go(url) { go(url) {
const pages = getCurrentPages(); if (url.indexOf(this.page) > -1) return;
const page = pages[pages.length - 1].route;
if (url.indexOf(page) > -1) return;
uni.switchTab({ url }) uni.switchTab({ url })
}, },
}, },
...@@ -56,6 +61,7 @@ ...@@ -56,6 +61,7 @@
justify-content: center; justify-content: center;
align-items: center; align-items: center;
gap: 12rpx; gap: 12rpx;
opacity: 0.7;
.icon { .icon {
width: 46rpx; width: 46rpx;
...@@ -68,5 +74,9 @@ ...@@ -68,5 +74,9 @@
color: #FFFFFF; color: #FFFFFF;
} }
} }
.item.active {
opacity: 1;
}
} }
</style> </style>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment