// 使用路径参数(需要在路由配置中定义参数) this.$router.push({ path: `/chat/${userId}` }); // 使用查询参数 this.$router.push({ path: '/chat', query: { userId: '123' } });
目标组件中获取参数
// 对于路径参数,在目标组件中使用$route.params获取
created() {
const userId = this.$route.params.userId;
},
// 对于查询参数,在目标组件中使用$route.query获取
created() {
const userId = this.$route.query.userId;
}