我正在尝试创建一个模式路由,并且当您使用路由器链接访问此路由器路径时,会在当前页面上方显示一个模式,或者如果我直接从URL访问上面的模态指数。Vuejs2 Modal with vue-router
例如:我在http://localhost/profile/1并点击侧边栏创建团队URL更改为http://localhost/team/creat,但模态后面的页仍为http://localhost/profile/1。
这是我想要的代码:
路由器:
Vue.component('modal', Modal);
export default new Router({
mode: 'history',
routes: [
{
path: '/',
name: 'Hello',
component: require('@/components/Hello'),
meta: { auth: false }
},
{
path: '/team',
name: 'team',
component: require('@/components/team/Index'),
meta: { auth: true },
},
{
path: '/team/create',
name: 'CreateTeam',
components: {
b: CreateTeam
},
meta: { auth: true }
},
]
})
App.vue
<template>
<router-view></router-view>
<!--This is the "MODAL" router-view -->
<router-view name="b"></router-view>
</template>
Modal.vue
<template>
<div class="modal">
<slot name="body"></slot>
<button type="button" @click="$emit('close')">×</button>
</div>
</template>
CreateTeam.vue
<template>
<modal @close="vm.$router.go(-1)">
<div slot="body" class="col-md-12">
Form here
</div>
</modal>
</template>
一切工作,而不是当我去/制作/团队背后的模式是空的
你的模式不应该在这种情况下,路由,它应该是相同的部件的要素是放置你的'路由器视图'。当需要显示它时,使用事件或状态管理从该组件中触发它,甚至通过'router-view'将一个函数传递给需要触发它的组件。 – Bert
我明白,但在这种情况下,我想打开任何组件像“全球模式”。如果我喜欢你说所有的组件都必须有模态组件和diferents路径的代码ex:profile/modal,team/modal“我想在任何地方打开团队/创建 – Snickfire
不,这不是我它应该生活在App.vue中,它不应该是一个路线,你的组件*是路线应该触发它。 – Bert