0👍
Try checking window.location.href to get current route on mounted() state of your routes and add the css on that condition
- [Vuejs]-Loopback throws errors Unprocessable Entity
- [Vuejs]-Why do i keep getting "connection to the server was unsuccessful. (http://localhost:12896/)"?
0👍
You could pass a class as a prop with the route:
https://router.vuejs.org/guide/essentials/passing-props.html
0👍
You could just use the most simple solution. put the route name on the surrounding div and target it with css. e.g.
.home .navbar {}
.about .navbar {}
Or as you are using router view you can get the current route path in your nav bar component and use this to create a computed property to return the class you need.
<nav :class="['some','class', backgroundColor]"></nav>
...
computed: {
backgroundColor() {
switch (this.$route.fullPath) {
case ('/'):
return 'bg-blue';
case ('/about'):
return 'bg-pink';
default:
return 'bg-red';
}
}
},
- [Vuejs]-Can't use vuetify variables in nuxt.js project
- [Vuejs]-Vue Animation inside the div element doesn't work
Source:stackexchange.com