[Vuejs]-How to fire an event in mount in Vuejs

0👍

So if I understand correctly, you want currentIndex to be a value that’s based on the current active route? You could create it as a computed property:

currentIndex: function(){
    let route = this.$router.currentRoute.name;
    
    if(router == 'profile') {
        return 0;
    } else if(router == 'my-tickets') {
        return 1;
    }
}

I think you could leverage Vue’s reactivity a lot more than you are doing now, there’s no need for multiple copies of the same element, you can just have the properties be reactive.

<div class="sidebar-content">
    {{ sidebar[currentIndex] }}
</div>

Also, you might consider having object be a computed property, something like this:

computed: {
    getUser() {
        return this.$store.state.user;
    },
    object() {
        return this.sidebar[currentIndex].products;
    }
},

0👍

Just use this.$route inside of any component template. Docs .You can do it simple without your custom logic checkRouter() currentIndex. See simple example:

<div class="sidebar-content">
     <div v-if="$route.name === 'profile'">
          Profile
      </div>
      <div v-if="$route.name === 'my-tickets'">
          Meine Tickets
       </div>
     </div>

Leave a comment