javascript - Vue router-view 加载父组件而不是它自己的
问题描述
我有这样的路由配置:
{
path: '/',
component: Dashboard,
meta: { requiresAuth: true },
children: [
{ path: 'home', components: { container: Home } },
{
path: 'post',
components: { container: Post },
children: [
{ path: 'add', components: { container: Add } }
]
},
]
},
我有两个<router-view>
s,一个是命名container
的,另一个是未命名的。我希望Add
组件在我访问时被加载到container
路由器视图/post/add
中。但它正在加载Post
组件。我错过了什么?
编辑:
Post.vue:
<template>
<div>
<p>I am <code>./views/post/Post.vue</code></p>
</div>
</template>
解决方案
试试这个,Post
从父组件中删除组件并添加一个新的子组件path: ''
。它看起来像这样 -
{
path: 'post',
component: // Include a component which only renders the router-view
children: [
{ path: '', components: { container: Post } },
{ path: 'add', components: { container: Add } }
]
},
创建了一个repl供您参考
推荐阅读
- api - 向 coinGecko API 发出请求时访问被拒绝错误 809
- migration - Microfocus ALM:如何使用分析视图中的 SQL 查询导出测试用例的附件
- microsoft-graph-api - 确定 Teams 会议是否开始
- android - 无法使用意图传递对象
- firebase - 如何在 Flutter 中将资产上传到 FirebaseStorage?
- jquery - 如何通过文件 .js 获取 jquery.data(element).actions 的结果?
- html - ajax调用后单击功能/连接未来元素不起作用
- azure - 如何使用 Power Shell 脚本从 Key Vault 获取证书?
- itext7 - iText7 翻转文本 - 错误?
- java - 打开一个片段,用能够返回的方式替换 nav_host