我正在使用Nuxt.js来构建静态网站。
如何访问组件的script
代码当前显示的路由名称(我想避免从浏览器位置读取直接URL)?
我可以以某种方式访问$route.name
?
是的,你可以使用vuejs路由对象,如$route.name
或$route.path
$nuxt.$route.path
返回当前路径
$nuxt.$route.name
当前路由的名称(如果有)。
路由对象表示当前活动路由的状态。它包含当前URL的解析信息以及URL匹配的路由记录。
**
data() {
return {
zone: this.$nuxt.$route.query.zone,
jour: this.$nuxt.$route.query.jour
} },
**
另一种方法是使用以下任一方法:
this.$route.path
→http://localhost:3000
的例子,{{this.$route.path}}
将打印/
this.$route.name
→http://localhost:3000
的例子,{{this.$route.name}}
将打印index