vue-router change only one of the named view without affecting the others

人盡茶涼 提交于 2019-12-12 21:06:49

问题


I am testing with vue-router and come across this problem, what if i have two named views but i only want to change one of it without changing the default view. Currently I do it like this:

const router = new VueRouter({
  routes: [
    {
      path: '/',
      components: {
        default: Foo,
        change: Bar,
      }
    }
    {
      path: '/foo/test1',
      components: {
        default: Foo,
        change: test1,
      }
    }

    //is it possible to do it something like this?
    {
      path: '/:foo/test1',
      components: {
        default: :foo//<--- how to keep default to whatever it previously have?
        change: test1
      }
    }

  ]
})
<router-view></router-view>
<router-view name="change"></router-view>

I think i can do this with dynamic matching, get the current route name and pass it as param, but I need to keep the current default route (like some form inputs), so i'd rather want to change only one of the views without affecting the others... please help...

来源:https://stackoverflow.com/questions/47666624/vue-router-change-only-one-of-the-named-view-without-affecting-the-others

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