在Nuxt.js中,我执行了以下文件夹结构:
├── parent
│ ├── child1.vue
│ └── child2.vue
├── parent.vue在parent.vue中,我有以下内容:
<template>
<div>
<h3>Parent element</h3>
<ul>
<li><nuxt-child/></li>
<li><nuxt-child/></li>
</ul>
</div>
</template>在child1.vue 1.中
<template>
<div>
<h3>Child 1</h3>
</div>
</template>在儿童期2.
<template>
<div>
<h3>Child 2</h3>
</div>
</template>我启动了服务器( server )并转到这个URI:http://localohost:3000/parent,在这里我看到了以下内容:
Parent element
-
- 如果我去http://localohost:3000/parent/child1,我会看到这个:
Parent element
- Child 1
- Child 1如果我去http://localohost:3000/parent/child2,我会看到这个:
Parent element
- Child 2
- Child 2问题:
从文档中,我了解到 children 1.vue和children 2. but 是parent.vue的子类,所以我希望在访问http://localhost:3000/parent时看到它们的列表,但它们没有显示。只有当我指向其URI时,才会显示每个子元素。有人能解释我的这种行为吗?
发布于 2018-10-04 14:34:14
<nuxt-child/>是基于路由的子组件的替代。
使用一个是你所需要的:
<template>
<div>
<h3>Parent element</h3>
<nuxt-child/>
</div>
</template>然后把你需要的东西放在孩子身上不同的地方。
编辑:子页面是根据路由引入的。这是一种手工操作嵌套路由的方法。
例如,假设我有一些活动。父页面是event,然后每个事件都是子事件。
- events
- christmas
- easter当我转到events/christmas或events/easter时,我会看到‘event’页面,但是有我想要的事件的内容。父页面events/可能只包含我要访问的所有事件的列表。
https://stackoverflow.com/questions/52649258
复制相似问题