1.简单值传递
(1)路径放入path:
(2)参数放入query:
传入:
单参:
this.$router.push({path:'/pages/mart/addCommunity',query:{doctorId:res.data.id}})
多参:
this.$router.push({path:"/pages/chat/chatIndex",query:{"userId":pat.doctorId,"toUserId":pat.patientsId}});
接参:
在传入时赋值
onLoad() {
this.doctorId=this.$route.query.doctorId;
console.log(this.doctorId);
},
效果:
2.关于对象的传参/接参的方法:
(1)JSON传参:
const patieStr = JSON.stringify(this.patie); // 将对象序列化为字符串
uni.navigateTo({
url: `/pages/addresses/addresses?patie=${encodeURIComponent(patieStr)}` // 对字符串进行编码,以支持特殊字符
});
接参:
if (options.patie) {
this.patie = JSON.parse(decodeURIComponent(options.patie)); // 解析并解码字符串
console.log(this.patie); // 使用解析后的对象
}