鍍金池/ 問答/HTML/ element-ui 菜單動態(tài)查詢的怎么默認打開某個菜單?

element-ui 菜單動態(tài)查詢的怎么默認打開某個菜單?

大致需要是:
從首頁跳轉(zhuǎn)到某模塊下邊時, 跳轉(zhuǎn)到目標頁面時。 從左邊展示的分類中找到最新分類。 在右邊區(qū)別展示對應(yīng)分類的內(nèi)容

template

左邊一個導(dǎo)航, 右邊是動態(tài)展示區(qū)域

<template>
  <el-container class="container">
    <el-aside width="200px">
      <art-nav/>
    </el-aside>
    <el-main>
      <router-view></router-view>
    </el-main>
  </el-container>
</template>

導(dǎo)航加載出來, 通過計算屬性 計算出 展廳第一個id, 設(shè)置到el-menu 的default-active里沒效果

<template>
  <el-menu class="menu" :default-active="activeIndex" mode="vertical"  router active-text-color="#AD9D79">
    <el-menu-item-group>
      <template slot="title">藏品</template>
      <el-menu-item v-for="item in artType" :key="item.id" :index="'/art/list/' + item.id">{{item.name |truncate}}</el-menu-item>
    </el-menu-item-group>
    <el-menu-item-group>
      <template slot="title">展廳</template>
      <el-menu-item v-for="item in hallList" :key="item.id" :index="'/art/hall/' + item.id">{{item.name |truncate}}</el-menu-item>
    </el-menu-item-group>
  </el-menu>
</template>

router

export default [
  {
    path: '/art',
    name: 'art',
    component: layout,
    children: [
      {
        path: 'hall/:id',
        component: HallDetail,
        props: true
      },
      {
        path: 'detial',
        component: detial
      }
    ]
  }
]

這樣的要怎么做?

PS: 計算屬性計算:
從vuex取結(jié)果帕映射到計算屬性, 然后再寫一個計算屬性,排序后拿第一個, 我懷疑default-active只有在組件 created時設(shè)置的

回答
編輯回答
真難過

default-active=“$router.path”

2018年3月10日 19:19
編輯回答
女流氓

最后的解決方案是:

  1. 修改vuex action返回值查詢包含data的Promise對象
  2. 給調(diào)用查詢展廳的dispatch添加then回調(diào)
  3. 在回調(diào)判斷路由path 等于/art時跳轉(zhuǎn)到計算后的展廳連接, 其它path時不處理
  4. 把導(dǎo)航到當前頁面的url改為/art
2018年1月16日 03:29
編輯回答
抱緊我

添加個默認路由 且給菜單加exact

2018年5月14日 14:18