优化导航栏链接,添加外部和内部链接打开功能,改进用户交互体验

This commit is contained in:
2025-03-06 09:06:21 +08:00
parent d1aad382c6
commit 9de7b643f3

View File

@ -1,5 +1,5 @@
<template> <template>
<el-menu mode="horizontal" router class="custom-menu"> <el-menu mode="horizontal" class="custom-menu">
<!-- 左侧网站名 --> <!-- 左侧网站名 -->
<div class="website-name"> <div class="website-name">
<span style="font-weight: bold">Kisechan </span> <span style="font-weight: bold">Kisechan </span>
@ -7,17 +7,25 @@
<!-- 右侧导航选项 --> <!-- 右侧导航选项 -->
<div class="menu-items"> <div class="menu-items">
<el-menu-item index="/">首页</el-menu-item> <el-menu-item @click="openLink('/')">首页</el-menu-item>
<el-menu-item @click="goToBlog">博客</el-menu-item> <el-menu-item @click="goToBlog">博客</el-menu-item>
<el-menu-item index="/links">友链</el-menu-item> <el-menu-item @click="openLink('/links')">友链</el-menu-item>
</div> </div>
</el-menu> </el-menu>
</template> </template>
<script setup> <script setup>
// 打开外部链接
const goToBlog = () => { const goToBlog = () => {
window.open("https://blog.kisechan.space", "_blank"); window.open("https://blog.kisechan.space", "_blank");
}; };
// 打开内部链接(新标签页)
const openLink = (path) => {
const fullUrl = "https://www.kisechan.space" + path; // 获取完整 URL
if (window.location.href === fullUrl) return; // 防止重复点击
window.open(fullUrl, "_blank");
};
</script> </script>
<style scoped> <style scoped>
@ -39,9 +47,10 @@ const goToBlog = () => {
.el-menu-item { .el-menu-item {
font-size: 16px; font-size: 16px;
cursor: pointer; /* 添加手型光标 */
} }
.website-name { .website-name {
font-size: 1.5em; font-size: 1.5em;
} }
</style> </style>