nuxt.js - 尽管使用了 Nuxt 根页面(父),但不会为子路由呈现在父母
问题描述
我有一个简单的文件设置:
页面结构:
./pages/index.vue // root page to be displayed for '/'
./pages/child.vue // sub-page to be displayed inside index.vue for '/child'
index.vue
:
<template>
<div>
<p>This is parent</p>
<some-component-from-components></some-component-from-components>
<nuxt-child />
</div>
</template>
child.vue
:
<template>
<div>
<p>This is Child</p>
</div>
</template>
我希望对于'/'
路由index.vue
将显示,对于嵌入在占位符中的'/child'
路由。路线按预期工作,但是显示了 for just 。index.vue
child.vue
<nuxt-child />
'/'
'/child'
child.vue
为什么?<nuxt-child />
不适用于根页面还是有其他问题?
解决方案
如果您想要这种行为,您需要将child
组件嵌套在目录中。index
在这里,您确实在同一级别上拥有两者,因此为什么您不能将一个嵌套到另一个中。
更多信息在这里:https ://nuxtjs.org/docs/2.x/features/nuxt-components#the-nuxtchild-component
有关路由结构的更多详细信息:https ://nuxtjs.org/docs/2.x/features/file-system-routing#nested-routes
推荐阅读
- amazon-web-services - Lambda 函数 s3.getObject 返回“内部服务器错误”
- powershell - 通过右键单击文件运行 GUI powershell 脚本
- shell - 使用 shell 脚本比较两个不同的数组
- java - 在java中将字符串日期转换为sql日期格式
- c# - 显示选定字节的小端值?
- javascript - React - 使用 componentDidUpdate 根据从另一个函数传递的数据更新状态
- r - 如何将 pdf() 函数 R 中的高度和宽度值与 pdf 分辨率值相匹配?
- javascript - 启动文件上传对话框的文本字段:如何获取文件名?
- google-apps-script - 使用 Apps 脚本将图像从 Google Drive 插入 Google Sheets
- python - 3类回归分析中的错误