在 Nuxt.js 中,如果我在 pages/posts/_id.vue
中有此代码:
<template>
<div>
Post id: {{$route.params.id }}
</div>
</template>
当我输入 URL:http://localhost:3000/posts/123
时,它会显示 Post id: 123。
于是我学会了如何通过URL传递一个参数。
但我还想传递帖子所属的类别并显示如下消息:帖子 ID:123。类别:新闻。
- 如何构建帖子文件夹并获得我想要的结果?
- 在这种情况下如何访问 URL?像
http://localhost:3000/posts/123
/News` 这样的东西?
最佳答案
参见 Dynamic Nested Routes在文档中。您的目录结构应如下所示:
posts/
--| _category/
-----| _id.vue
URL 将为 http://localhost:3000/posts/news/123
。
您可以使用 {{ $route.params.category }}
访问类别参数。
关于javascript - Nuxt中如何传递多个参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52357328/