[Vuejs]-Vue.js component nav active class only applies on second click

0👍

Just figured it out.. instead of adding a click event I used the created method built into vue.js:

created() {
    for (let i = 0; i < this.menuItems.length; i++) {
        this.menuItems[i].active = false;
        if (this.menuItems[i].url === this.$router.currentRoute.path) {
            this.menuItems[i].active = true;
        }
    }
}

I’m still wondering if this is the best way to do this?

Leave a comment