【问题标题】:Nuxt app freezing while using nested routes使用嵌套路由时 Nuxt 应用程序冻结
【发布时间】:2019-09-01 04:20:08
【问题描述】:

在索引(主页)中,如果我单击一个按钮并导航到:

http://localhost:3000/browse/songs/new

它冻结了浏览器并且没有响应并显示空白页面!

但是,如果我手动输入这个 url,它就可以工作。

我的页面目录结构:

--browse
    --songs
        --new
            index.vue

browse.vue
index.vue

我在 github 上发现了一个问题,但对我没有帮助!

App freezes while using nuxt-link and nested routes with redirect

【问题讨论】:

  • 在代码沙箱或 github 上创建复制品。没有代码是不可能的

标签: vue.js vuejs2 nuxt.js


【解决方案1】:

看起来您的问题实际上与您链接到的 github 上的问题有关。

如果我理解正确,您的页面目录是这样的:

|-browse (folder)
|  |-songs (folder)
|    |-new (folder)
|      index.vue (file)
|-browse.vue (file)
|-index.vue (file)

这会对 nuxt 造成混淆,因为您基本上有两个不同的东西试图成为同一个东西,您的“浏览”文件夹和您的“浏览”文件。

你应该这样尝试:

|-browse (folder)
|  |index.vue (file) //this replaces your browse.vue file and can be found at http://localhost:3000/browse
|  |-songs (folder)
|    |-new (folder)
|      index.vue (file) //this can be found at http://localhost:3000/browse/songs/new
|-index.vue (file)

如果上述破坏了 nuxt-child 安排,则以下似乎可行。

|-browse (folder)
|  |index.vue (file) 
|  |-songs (folder)
|    |-index.vue 
|    |-new (folder)
|      index.vue (file) 
|-browse.vue
|-index.vue (file)

由于路由的嵌套,要找到每个路由的<nuxt-child/>,您需要将其包含在每个级别的 index.vue 中。该文件可以包含以下内容:

//browse-index.vue && browse-songs-index.vue
<template>
  <div>
    <nuxt-child/>
  </div>
</template>

但它使子链保持活动状态。

【讨论】:

  • 但是使用这种结构,我有问题。在 |-browse , index.vue 我有两个组件应该加载到子页面中。在浏览 index.vue 我有 但它不会在歌曲/新/index.vue 中呈现这些组件。我该怎么办?
  • 是的,那会是个问题。我认为您的文件夹过于嵌套而无法与 nuxt-child 一起正常工作,并且可能会导致您原来的问题。据我所知,为了让 nuxt-child 工作,孩子应该只有一层深。如果您需要该结构,则可以改用常规组件结构。或者发布一些代码供@Aldarund 看,他是这类事情的大师。
  • 什么是regular component structure
  • 我的意思是一个普通的组件。因此,如果您希望 /browse/songs/new 看起来像 /browse 但带有一些附加内容,请在 browse-index.vue 和 browse-songs-new-index.vue 中使用一个组件并添加附加内容(我猜是新歌)在组件之后。想到别的了...我会编辑答案。
  • 新结构(browse.vue)再次冻结
猜你喜欢
  • 2019-03-13
  • 1970-01-01
  • 2020-04-17
  • 1970-01-01
  • 2021-01-20
  • 1970-01-01
  • 2015-01-09
  • 2020-08-11
  • 2019-04-14
相关资源
最近更新 更多