在 Nuxt.js 中如何将用户名动态添加到 URL,例如 http://localhost:3001/profile 和 http://localhost:3001/profile/@user

问题描述 投票:0回答:1
  • 页面/profile.vue
  • pages/_username.vue

在 Nuxt.js 中处理两个 URL — http://localhost:3001/profile (通用配置文件路由)和 http://localhost:3001/profile/@user (动态用户名路由) 无意义的文字 hh3hwbhbwehcdcewusbdjdbojqhwebfoherjbfhgervdogvfredjsbfrejvsofjhreufoergoufhoehr dcewusbdjdbojqhwebfoherjbfhgervdogvfredjsbfrejvsofjhreufoergoufhoehr dcewusbdjdbojqhwebfoherjbfhgervdogvfredjsbfrejvsofjhreufoergoufhoehrb

vue.js nuxt.js
1个回答
0
投票

为此,您需要创建下一个文件夹结构

-| pages/
---| profile/
-----| index.vue
-----| [usernane].vue

然后在你的组件中你可以使用

获取用户名
<script setup lang="ts">
const route = useRoute()
console.log(route.params.username)
</script>

参考:https://nuxt.com/docs/getting-started/routing

© www.soinside.com 2019 - 2024. All rights reserved.