考虑一下:
this.$root.$router.push({
path: '/dashboard',
params: { errors: 'error' },
query: { test: 'test' }
})
我在我的组件中使用它来重定向到另一个 URL,但出现了一些错误。问题是,当我想访问仪表板组件中的 params
字段时,它是空的。 query
字段运行良好。我正在尝试通过 this.$route.params.errors
访问它。
最佳答案
您只能将 params
与 named
路径一起使用(我认为)。
例子:
//route (in your router file should have "name")
{ path: '/errors', name: 'EXAMPLE', component: ... }
//navigating
this.$router.push({
name: 'EXAMPLE',
params: { errors: '123' }
});
现在它将在 this.$route.params
中具有正确的值。
关于vue.js - $router.push 中的参数字段为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40680707/