I have been considering adding a data-attribute to the body of my vue
-app that would display the current route's name. I prefer not to utilize the vue-body-class package and want to keep it simple.
Currently, I am implementing this in each of my main components, such as the About.vue
:
mounted() {
document.body.setAttribute("data-route", this.$route.name);
},
destroyed() {
document.body.removeAttribute("data-route", this.$route.name);
}
This method works fine, but I am exploring if there might be a more efficient way to achieve this. Perhaps in the router.js
file?
Any suggestions or insights are appreciated.