(推荐)
订单确认页 + 用户ID → 用 storage 或 eventChannel
✅ 推荐写法一:eventChannel(最适合你现在这个跳转)
发送页面
uni.navigateTo({ url: '/pages/order/orderConfirm', success(res) { res.eventChannel.emit('juzhongyi', { aa: 145 }) } })⚠️ 注意:如果在 methods 里,
this要先保存
const that = this uni.navigateTo({ url: '/pages/order/orderConfirm', success(res) { res.eventChannel.emit('juzhongyi', { aa: 145 }) } })接收页面
全局定义一个变量,aa
onLoad() { const eventChannel = this.getOpenerEventChannel() eventChannel.on('juzhongyi', data => { this.aa = data.aa console.log("this.aa after event",JSON.stringify(this.aa)) }) }✅ 推荐写法二:storage(支付流程最稳)
跳转前
uni.setStorageSync('orderConfirm', { order, userid: this.userid }) uni.navigateTo({ url: '/pages/order/orderConfirm' })接收页
onLoad() { const data = uni.getStorageSync('orderConfirm') this.order = data.order this.userid = data.userid }四、什么时候 URL 传参才是合适的?
| 场景 | URL |
|---|---|
| ID / type / page | ✅ |
| 简单字符串 | ✅ |
| 对象 | ❌ |
| 订单 | ❌ |
| 支付参数 | ❌ |