fix: 修复导航栏跳转异常的问题
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref, watch } from 'vue';
|
import { computed, ref, watch } from 'vue';
|
||||||
import { useRoute, useRouter } from 'vue-router';
|
import { useRoute, useRouter } from 'vue-router';
|
||||||
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
@@ -14,7 +14,7 @@ const navigation = ref([
|
|||||||
},
|
},
|
||||||
// icon: '/tabbar/home.png',
|
// icon: '/tabbar/home.png',
|
||||||
icon: 'home-o',
|
icon: 'home-o',
|
||||||
inactive:''
|
inactive: ''
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: '伊调研',
|
title: '伊调研',
|
||||||
@@ -22,7 +22,7 @@ const navigation = ref([
|
|||||||
// name: 'home',
|
// name: 'home',
|
||||||
// path: '/home'
|
// path: '/home'
|
||||||
// },
|
// },
|
||||||
// icon: '/tabbar/yl.png'
|
icon: '/tabbar/yl.png'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: '我的',
|
title: '我的',
|
||||||
@@ -30,14 +30,16 @@ const navigation = ref([
|
|||||||
name: '',
|
name: '',
|
||||||
path: '/survey'
|
path: '/survey'
|
||||||
},
|
},
|
||||||
icon:'friends-o',
|
icon: 'friends-o'
|
||||||
// icon: '/tabbar/mine.png'
|
// icon: '/tabbar/mine.png'
|
||||||
}
|
}
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// 当前的 nav
|
// 当前的 nav
|
||||||
const currentNav = navigation.value.find((item) => item.link.path === route.fullPath);
|
const currentNav = computed(() =>
|
||||||
const activeTab = ref(currentNav?.title);
|
navigation.value.find((item) => item?.link?.path === route.fullPath)
|
||||||
|
);
|
||||||
|
const activeTab = ref(currentNav.value?.title);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle changing of navigation
|
* Handle changing of navigation
|
||||||
@@ -47,42 +49,50 @@ function handleChangeNav(title: string) {
|
|||||||
const nav = navigation.value.find((item) => item.title === title);
|
const nav = navigation.value.find((item) => item.title === title);
|
||||||
const params: { [key: string]: string } = {};
|
const params: { [key: string]: string } = {};
|
||||||
// 如果有 name 表示,优先取 name 参数
|
// 如果有 name 表示,优先取 name 参数
|
||||||
nav && nav.link.name.length !== 0
|
nav && nav.link?.name.length !== 0
|
||||||
? (params.name = nav.link.name as string)
|
? (params.name = nav?.link?.name as string)
|
||||||
: (params.path = nav?.link.path as string);
|
: (params.path = nav?.link?.path as string);
|
||||||
router.push(params);
|
router.push(params);
|
||||||
}
|
}
|
||||||
|
|
||||||
watch(activeTab, (value: string) => {
|
watch(activeTab, (value) => {
|
||||||
handleChangeNav(value);
|
handleChangeNav(value as string);
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div class="navigation">
|
<van-tabbar v-model="activeTab" class="navigation">
|
||||||
{{activeTab}}
|
<template v-for="(item, index) in navigation" :key="item.title">
|
||||||
<van-tabbar v-model="activeTab">
|
<span
|
||||||
<van-tabbar-item v-for="item in navigation"
|
v-if="index === 1"
|
||||||
:icon="item.icon" :key="item.title" :name="item.title">
|
style="
|
||||||
<!-- <template #icon="props">-->
|
display: flex;
|
||||||
<!-- <img :src="props.active ? icon.icon : icon.inactive" />-->
|
flex-flow: column nowrap;
|
||||||
<!-- </template>-->
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
"
|
||||||
|
>
|
||||||
|
<img :src="item.icon" alt="" style="width: 30px; height: 30px" />
|
||||||
|
{{ item.title }}
|
||||||
|
</span>
|
||||||
|
<van-tabbar-item v-else :icon="item.icon" :name="item.title">
|
||||||
{{ item.title }}
|
{{ item.title }}
|
||||||
</van-tabbar-item>
|
</van-tabbar-item>
|
||||||
|
</template>
|
||||||
</van-tabbar>
|
</van-tabbar>
|
||||||
</div>
|
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<style scoped lang="scss">
|
<style scoped lang="scss">
|
||||||
.navigation {
|
.navigation {
|
||||||
width: 100vw;
|
padding: 3px 0;
|
||||||
background-color: white;
|
// width: 100vw;
|
||||||
display: flex;
|
// background-color: white;
|
||||||
flex-flow: row;
|
// display: flex;
|
||||||
justify-content: space-around;
|
// flex-flow: row;
|
||||||
position: fixed;
|
// justify-content: space-around;
|
||||||
bottom: 0px;
|
// position: fixed;
|
||||||
z-index: 10;
|
// bottom: 0px;
|
||||||
|
// z-index: 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
.navigation-item {
|
.navigation-item {
|
||||||
|
|||||||
Reference in New Issue
Block a user