Files
edgeKey/components/Link.vue
2026-04-21 11:56:35 +08:00

28 lines
550 B
Vue

<template>
<a :class="{ active: isActive }">
<slot />
</a>
</template>
<script lang="ts" setup>
import { usePageContext } from "vike-vue/usePageContext";
import { computed, useAttrs } from "vue";
const pageContext = usePageContext();
const { href } = useAttrs();
const isActive = computed(() => {
const { urlPathname } = pageContext;
return href === "/" ? urlPathname === href : urlPathname.startsWith(href);
});
</script>
<style scoped>
a {
padding: 2px 10px;
margin-left: -10px;
}
a.active {
background-color: #eee;
}
</style>