在 Nuxt.js 中处理两个 URL — http://localhost:3001/profile (通用配置文件路由)和 http://localhost:3001/profile/@user (动态用户名路由) 无意义的文字 hh3hwbhbwehcdcewusbdjdbojqhwebfoherjbfhgervdogvfredjsbfrejvsofjhreufoergoufhoehr dcewusbdjdbojqhwebfoherjbfhgervdogvfredjsbfrejvsofjhreufoergoufhoehr dcewusbdjdbojqhwebfoherjbfhgervdogvfredjsbfrejvsofjhreufoergoufhoehrb
为此,您需要创建下一个文件夹结构
-| pages/
---| profile/
-----| index.vue
-----| [usernane].vue
然后在你的组件中你可以使用
获取用户名<script setup lang="ts">
const route = useRoute()
console.log(route.params.username)
</script>