To efficiently handle this situation, you can establish a computed property named isTop
that will evaluate to true if the user is currently on the "Top page."
If the menu
is a subcomponent, you can transmit a prop to it like this:
<menu :isTop='isTop'>
Then, utilize Vue's conditional class syntax inside the child component to dynamically apply the appropriate CSS class depending on the value of isTop
:
// Child component template:
<div :class='[{"menuTop": isTop}, {"menuGeneral": !isTop}]'>
...
</div>
If you intend to use the <menu>
HTML tag directly, you can apply a similar syntax to it without using a child component:
<menu :class='[{"menuTop": isTop}, {"menuGeneral": !isTop}]'></menu>
In both cases, your computed property will resemble this:
computed: {
isTop: function() {
// The method to determine if you are on the "Top page" goes beyond the scope of this discussion.
// For instance, with Vue Router, you could compare the current route with the Top page's route.
// Return true if you are on the "Top page" and false otherwise.
}
}
Your stylesheet will then include something along these lines:
<style>
.menuTop {
color: blue;
}
.menuGeneral{
color: green;
}
</style>