鍍金池/ 問答/HTML/ vue.js中怎樣根據(jù)$route.path快速找到對應(yīng)的route對象?

vue.js中怎樣根據(jù)$route.path快速找到對應(yīng)的route對象?

我定義了一個路由,有兩個children:

  {
    path: '/example',
    component: Layout,
    redirect: 'noredirect',
    name: 'Example',
    children: [
      { path: 'index', name: 'Form1', icon: 'zonghe', component: _import('page/form') },
      { path: 'index2', name: 'Form2', icon: 'zonghe', component: _import('page/form') },
    ]
  },

現(xiàn)在拿到一個route.path等于/example/index2,以及route.js里面的route map,有快捷的方式找到對應(yīng)的route項(xiàng)么?是不是必須逐個進(jìn)行path字符串的截取匹配?

回答
編輯回答
柚稚

this.$route可以獲取當(dāng)前路由下的相關(guān)內(nèi)容
比如this.$route.name // 'Form1'
this.$route.icon // 'zonghe'

2018年3月17日 14:21