【问题标题】:How to pass multiple parameters in Nuxt?Nuxt如何传递多个参数?
【发布时间】:2018-09-16 18:43:32
【问题描述】:

如果我在 pages/posts/_id.vue 中有此代码,则在 Nuxt.js 中:

<template>                                                                                                                                                              
  <div>                                                                                                                                                                 
    Post id: {{$route.params.id }}                                                                                                                                    
  </div>                                                                                                                                                                
</template> 

当我输入 URL:http://localhost:3000/posts/123 时,它会显示 Post id: 123

所以我学会了如何通过 URL 传递一个参数。
但我还想传递帖子所属的类别并显示类似这样的消息:Post id: 123. Category: News

  • 如何构建帖子文件夹并获得我想要的结果?
  • 在这种情况下如何访问 URL? http://localhost:3000/posts/123/News 之类的?

【问题讨论】:

    标签: javascript vue.js nuxt.js


    【解决方案1】:

    请参阅文档中的Dynamic Nested Routes。您的目录结构应如下所示:

    posts/
    --| _category/
    -----| _id.vue
    

    网址将是http://localhost:3000/posts/news/123

    您可以使用{{ $route.params.category }} 访问类别参数。

    【讨论】:

      猜你喜欢
      • 2020-08-24
      • 2016-06-03
      • 1970-01-01
      • 1970-01-01
      • 2019-03-10
      • 2022-11-10
      • 2016-04-18
      • 2013-11-21
      • 2012-01-06
      相关资源
      最近更新 更多