fix: header nav 选中样式

This commit is contained in:
就眠儀式 2022-04-01 22:22:45 +08:00
parent 425cff9de5
commit 0c32eb1df5
2 changed files with 26 additions and 11 deletions

View File

@ -14,18 +14,18 @@
class="layui-nav layui-layout-left" class="layui-nav layui-layout-left"
style="margin-top: 0px; margin-bottom: 0px" style="margin-top: 0px; margin-bottom: 0px"
> >
<li class="layui-nav-item"> <li class="layui-nav-item" :class="{ 'layui-active':currentPath.includes('/zh-CN/index') }">
<router-link to="/zh-CN/index"> {{ t("nav.home") }} </router-link> <router-link to="/zh-CN/index"> {{ t("nav.home") }} </router-link>
</li> </li>
<li class="layui-nav-item"> <li class="layui-nav-item" :class="{ 'layui-active':currentPath.includes('/zh-CN/guide') }">
<router-link to="/zh-CN/guide"> {{ t("nav.guide") }} </router-link> <router-link to="/zh-CN/guide"> {{ t("nav.guide") }} </router-link>
</li> </li>
<li class="layui-nav-item"> <li class="layui-nav-item" :class="{ 'layui-active':currentPath.includes('/zh-CN/components') }">
<router-link to="/zh-CN/components"> <router-link to="/zh-CN/components">
{{ t("nav.components") }} {{ t("nav.components") }}
</router-link> </router-link>
</li> </li>
<li class="layui-nav-item"> <li class="layui-nav-item" :class="{ 'layui-active':currentPath.includes('/zh-CN/resources') }">
<router-link to="/zh-CN/resources"> <router-link to="/zh-CN/resources">
{{ t("nav.resources") }} {{ t("nav.resources") }}
</router-link> </router-link>
@ -224,7 +224,6 @@ export default {
const route = useRoute(); const route = useRoute();
const router = useRouter(); const router = useRouter();
const locale = ref("zh_CN"); const locale = ref("zh_CN");
const currentPath = ref("/zh-CN/guide");
const isDark = ref(false); const isDark = ref(false);
const locales = [ const locales = [
{ name: "zh_CN", locale: zh_CN, merge: true }, { name: "zh_CN", locale: zh_CN, merge: true },
@ -249,7 +248,17 @@ export default {
}); });
const menus = []; const menus = [];
const currentPath = ref("/zh-CN/guide");
watch(
() => route.path,
(val) => {
currentPath.value = val;
},
{
immediate: true,
deep: true,
}
);
menu.forEach((m) => { menu.forEach((m) => {
m.children.forEach((c) => { m.children.forEach((c) => {
menus.push(c); menus.push(c);
@ -301,6 +310,7 @@ export default {
handleClick, handleClick,
changeLocale, changeLocale,
themeVariable, themeVariable,
currentPath,
layuiVueVersion, layuiVueVersion,
}; };
}, },
@ -308,6 +318,7 @@ export default {
</script> </script>
<style> <style>
.layui-layout-document > .layui-header { .layui-layout-document > .layui-header {
z-index: 99; z-index: 99;
width: 100%; width: 100%;
@ -358,6 +369,10 @@ export default {
background-color: transparent; background-color: transparent;
} }
.layui-header > .layui-nav .layui-active * {
color: var(--global-checked-color)!important;
}
.layui-header .layui-local-badge { .layui-header .layui-local-badge {
font-size: 12.4px; font-size: 12.4px;
background: transparent; background: transparent;

View File

@ -35,7 +35,7 @@ const props = withDefaults(defineProps<LayButtonProps>(), {
loading: false, loading: false,
disabled: false, disabled: false,
nativeType: "button", nativeType: "button",
borderStyle: "solid" borderStyle: "solid",
}); });
const emit = defineEmits(["click"]); const emit = defineEmits(["click"]);
@ -48,9 +48,9 @@ const onClick = (event: any) => {
const styles = computed(() => { const styles = computed(() => {
return { return {
'border-style': props.borderStyle "border-style": props.borderStyle,
} };
}) });
const classes = computed(() => { const classes = computed(() => {
return [ return [