In vue-cli, how to add a class to an element of the page to change the style according to the natural route as a condition.

now you need to change the style of an element on the page based on the current route when the page jumps to a route.
Boss, don"t just talk about ideas, but also talk about the specific implementation code. I am relatively bad, a lot of grammar is not very familiar with, please!

Mar.05,2021

 routeName:this.$route.name,
:class="{'active':routeActive==='home'}"
  1. get the name of the current route;
  2. bind with vue style;
  3. just write the style according to this active

extract this part of the function into a component, then use watch to listen for routing changes, and then set the component style according to the style of each route you want to use

Menu