Vuetify list : open group according to active route

ぃ、小莉子 提交于 2021-02-11 12:37:57

问题


Let's suppose I have a Vuetify list with 2 v-list-group, each one containing a v-list-tile. Here is a simplified pseudo-code:

 - Group1
   - Item 1 :to='/item1'
 - Group2
   - Item 2 :to='/item2'

My list works fine : if I click on "Item1", vue-router goes to "/item1".

Conversely, when I go to some route '/item1' (by typing the URL for example) and Group1 is closed in the list, is it possible to make Group1 to automatically open in the list?

Do I have to watch route and use v-list-group.value to set the open group, or does Vuetify have something to do this automatically?


回答1:


Here is my solution using route watch : https://codesandbox.io/s/vuetify-router-template-0176-vy766 (based on Daniel's code).

The insteresting part is in Nav.vue:`

watch: {
  $route(to, from) {
    if (to.matched.length > 1) {
      const parent = to.matched.filter(m => !m.parent)[0];
      const route = routes.filter(route => route.name === parent.name)[0];
      route.active = true;
    }
  }
}


来源:https://stackoverflow.com/questions/56821172/vuetify-list-open-group-according-to-active-route

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!