123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- <template>
- <view class="hc-tabbar-box">
- <view class="hc-tabbar">
- <template v-for="item in tabbar" :key="item.path">
- <view class="item" :class="tabKey === item.path ? 'cur':''" @click="itemClick(item)">
- <view class="icon-box">
- <view class="icon">
- <text :class="item.icon"/>
- </view>
- </view>
- <view class="name">{{ item.name }}</view>
- </view>
- </template>
- </view>
- </view>
- </template>
- <script setup>
- import {onMounted, ref} from "vue";
- import {onShow} from '@dcloudio/uni-app'
- const tabKey = ref('pages/index/index')
- const tabbar = [
- {path: 'pages/index/index', name: '应用主页', icon: 'i-material-symbols-gamepad-rounded'},
- {path: 'pages/task/index', name: '任务消息', icon: 'i-ooui-message'},
- {path: 'pages/my/index', name: '我的', icon: 'i-material-symbols-person'},
- ];
- const itemClick = ({path}) => {
- tabKey.value = path;
- uni.switchTab({
- url: '/' + path,
- })
- }
- //渲染完成
- onMounted(() => {
- setTabbarData();
- })
- const setTabbarData = () => {
- uni.hideTabBar({
- animation: false
- });
- let pages = getCurrentPages();
- let currentPage = pages[pages.length - 1]
- tabbar.forEach(({path}) => {
- if (path === currentPage.route) {
- tabKey.value = path;
- }
- })
- }
- onShow(() => {
- setTabbarData();
- })
- </script>
- <style scoped lang="scss">
- @import "./style.scss";
- </style>
|