Vue-router不会推送到给定的名称

时间:2018-04-11 03:43:01

标签: vue.js vue-router

在我的项目中,我的路线:

New-BrokerHostingPowerAction -Action Shutdown -MachineName "$domain_name\$machine_name'

我的项目中有const routes = [{ path: '/', meta: { title: '' }, component: (resolve) => require(['./views/index.vue'], resolve), children: [ { path: 'a', name: 'a', title:'a', component: (resolve) => require(['./views/a/a.vue'], resolve) }, { path: 'b', name: 'b', title:'b', component: (resolve) => require(['./views/b/b.vue'], resolve), children: [ { path: 'c', name: 'c', title:'c', component: (resolve) => require(['./views/b/ccc.vue'], resolve) }, ] }, ] }]; index.vuea.vueb.vue个组件。

我的c.vue模板中有<Menu>

index.vue

您看到菜单<Menu mode="horizontal" active-name="1" @on-select="select_item"> <MenuItem name="a"> <Icon type="ios-paper"></Icon> go to a </MenuItem> <MenuItem name="b"> <Icon type="ios-people"></Icon> go to b </MenuItem> <MenuItem name="c"> <Icon type="settings"></Icon> go to c </MenuItem> </Menu> 绑定到@on-select方法,并在脚本的方法中返回名称,并按名称推送到路径:

select_item

我点击了MenuItem select_item(name){ console.log(name) this.$router.push({name: name}) } go to a一切正常,但是当我点击go to b时,它无效。

我检查了我的代码,但我不知道问题出在哪里。

1 个答案:

答案 0 :(得分:0)

bc中有嵌套路线:

{
  path: 'b',
  name: 'b',
  title:'b',
  component: (resolve) => require(['./views/b/b.vue'], resolve),
  children: [
    {
      path: 'c',
      name: 'c',
      title:'c',
      component: (resolve) => require(['./views/b/ccc.vue'], resolve)
    },
  ]
},

index.vue&#39; <router-view>是该组件的最高导出,您的路线中的导出为/a/b/b/c b.vue <router-view>中应该 { path: 'c', name: 'c', title:'c', component: (resolve) => require(['./views/b/ccc.vue'], resolve) },

要解决您的问题,您应该提出

a

与路线b和路线<router-view/>处于同一级别。

或者,您应该在b.vue中添加 $(document).on('focusout','#addedstudent-id',function() { console.log('d'); }); ,您可以看到效果。