首页 > 解决方案 > 路由器视图外的Vue路由返回空数据

问题描述

我正在努力在<router-view>组件之外获取 Vue 路由。在里面,它工作正常。

情况很奇怪,因为结果是这样的:

mounted : function()
{
    console.log(this.$router);
},

它显示了这一点:

currentRoute: Object
fullPath: "/activity-calendar"
hash: ""
matched: [{…}]
meta: {__ob__: Observer}
name: "Activity calendar"
params: {}
path: "/activity-calendar"
query: {}

这是对的。但是,当我尝试通过

console.log(this.$router.currentRoute);

我得到:

fullPath: "/"
hash: ""
matched: []
meta: {}
name: null
params: {}
path: "/"
query: {}

怎么,对象不一样?

标签: vue.jsvue-router

解决方案


推荐阅读