如何在Nuxt中传递多个参数?

JavaScript Vue.js

樱小胖Mandy

2020-04-03

如果我在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传递一个参数。
但我也想传递帖子所属的类别并显示如下消息:帖子ID:123。类别:新闻

  • 如何构造posts文件夹并获得所需的结果?
  • 以及在这种情况下如何访问URL?http://localhost:3000/posts/123/ News`一样?

第3940篇《如何在Nuxt中传递多个参数?》来自Winter(https://github.com/aiyld/aiyld.github.io)的站点

1个回答
十三 2020.04.03

请参阅文档中的动态嵌套路由您的目录结构应如下所示:

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

该网址将为http://localhost:3000/posts/news/123

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

问题类别

JavaScript Ckeditor Python Webpack TypeScript Vue.js React.js ExpressJS KoaJS CSS Node.js HTML Django 单元测试 PHP Asp.net jQuery Bootstrap IOS Android