mirror of
https://github.com/34892002/edgeKey.git
synced 2026-05-06 23:33:10 +08:00
28 lines
550 B
Vue
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>
|