使用 router.push 发送到其他组件的字符串未定义

string which is sent to other compononent with router.push is undefined

好吧,我有两个组成部分。我想从一个组件发送一个字符串到另一个组件,该字符串应该显示在控制台上。这是将数据推送到其他组件的组件:

this.$router.push({path: "/editService", params:{data: 'test'}})

这是第二个组成部分。此处应显示字符串:

    export default {
  data(){
    return{
      ServiceData: []
    }
  },
  created() {
    this.ServiceData=this.$route.params.data
    console.log(this.ServiceData)
  }

}

如果您使用的是 Vue Router,那么您应该定义一个类似于

的路由
{
   path: '/editService/:routeData',
   component: User,
   props: true
}

然后向您的用户组件添加一个道具:

export default {
  data(){
    return{
      ServiceData: this.routeData
    }
  },
  props: {
    routeData: {
      type: String, // at least for test
      required: true
    }
  },
  created() {
    console.log(this.ServiceData)
  }
}