Vue Router params 参数接收为空

89 阅读1分钟

push 函数里使用 pathparams 传参, B.vue 中 this.$route.params 接收为空

A.vue

let content = this.info
this.$router.push({ path: 'B', params: { content: content } })

B.vue

console.log(this.$route.params)  // {}

push 函数中使用 nameparams 进行传参即可使用 this.$route.params 正常接受参数

A.vue 正确跳转路由传参如下例子

let content = this.info
this.$router.push({ name: 'B', params: { content: content } })

B.vue 的 mounted 函数中接收

console.log(this.$route.params)  // { 'name': '123' }