我正在使用Nuxt.js构建一个静态网站。
如何在组件的script
代码中访问当前显示的路由名称(我想避免从浏览器位置读取直接的url )?
我能以某种方式访问$route.name
吗?
发布于 2017-06-26 03:53:46
可以,您可以使用$route.name
或$route.path
等vuejs路由对象
$nuxt.$route.path
返回电流路径
$nuxt.$route.name
当前路由的名称(如果有)。
路由对象表示当前活动路由的状态。包含当前URL的解析信息以及与该URL匹配的路由记录。
- type: string
- A string that equals the path of the current route, always resolved as an absolute path. e.g. "/foo/bar".
- type: string
- The full resolved URL including query and hash.
**
,如果您想要获取url参数。像这样:
你可以这样做:
data() {
return {
zone: this.$nuxt.$route.query.zone,
jour: this.$nuxt.$route.query.jour
} },
**
https://stackoverflow.com/questions/44748575
复制相似问题