【问题标题】:nuxt-child doesn't render the parent componentnuxt-child 不渲染父组件
【发布时间】:2019-04-15 08:20:48
【问题描述】:

我的文件夹结构是这样的:

|-profile
|-- index.vue
|-- address/index.vue

然后我执行<nuxt-child />,它不会呈现profile/index.vue 的内容!它只是加载了一条全新的路线。请帮忙!

【问题讨论】:

    标签: javascript vue.js nuxt.js


    【解决方案1】:

    上面的文件夹结构将创建一个全新的路由,而不是嵌套的。

    您可以在 Nuxt.js Routing 文档示例中看到完全相同的结构。

    nested routes 的示例也可在文档中找到

    在您的情况下,为了在<nuxt-child> 中呈现嵌套路由,以下结构将起作用:

    |-pages/
    |--| profile/
    |-----| address.vue
    |-----| index.vue
    |--| profile.vue
    

    并且<nuxt-child> 标签应该在profile.vue 页面内。这样profile/index.vue将在用户导航到/profile时呈现,address.vue将在用户导航到/profile/address时呈现。

    【讨论】:

    • 不适合我,如果你的个人资料是 _profile 意思是动态的,你会怎么做
    • 您也可以这样做,但对于 .vue 文件和文件夹都使用 _(下划线)。请参阅documentation 中的示例
    • @aBiscuit 我使用相同的方法,但是当启用keep-alive 时,它会导致profile 页面缓存并显示其他子页面(例如address.vue 在您的情况下)并且不显示profile/index.vue 内容。任何想法如何解决这个问题?
    猜你喜欢
    • 2020-07-20
    • 2019-06-20
    • 2018-08-12
    • 1970-01-01
    • 2018-01-10
    • 2019-03-09
    • 2020-12-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多