Vue.js Vuejs通过路由器将数据作为道具传递给组件
我想将一个Id从我的组件传递给另一个与父级或子级无关的组件。 我在一个个人资料页面上,点击一个按钮,它会把我带到一个消息页面 我进入另一页的方式:Vue.js Vuejs通过路由器将数据作为道具传递给组件,vue.js,vue-router,Vue.js,Vue Router,我想将一个Id从我的组件传递给另一个与父级或子级无关的组件。 我在一个个人资料页面上,点击一个按钮,它会把我带到一个消息页面 我进入另一页的方式: this.$router.push({ name: `messages_new` }); 在我的消息组件上,我应该收到此道具中联系人的ID: props: { sendTo: { type: Object, default: () => ({ to: [] }),
this.$router.push({ name: `messages_new` });
在我的消息组件上,我应该收到此道具中联系人的ID:
props: {
sendTo: {
type: Object,
default: () => ({
to: []
}),
description: 'Pre fill the send field with this receivers formatted {contact, type}'
}
},
我以这种方式尝试作为示例,以查看数据是否正在从联系人页面组件传递到消息组件:
data(){
sendTo: {
to: [{
contact: {
email: 'exemple@9online.fr',
first_name: 'exemple',
last_name: 'exemple',
_id: '12'
},
type: 'contacts'
}]
}
}
`this.$router.push({ name: `message_new`, params: { sendTo: this.sendTo} });`
但它不起作用,我所做的有什么不对劲吗,我是忘记了什么还是完全错了
[编辑]
我的路线设置如下:
{
name: 'profile',
path: '/profile/:id',
component: Profile,
props: (route) => ({ id: route.params.id || null }),
}
我的道具已经用联系人的id设置好了只需在router.js中为您的路线添加道具:true,如下所示:
{ path: '/Profile', name: 'Profile', component: load('ProfileComponent'), props: true}
谢谢你的回答,我编辑了关于道具的帖子