uni-app的代码传参hbuilderx
2026/7/17 8:18:23 网站建设 项目流程

(推荐)

订单确认页 + 用户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
简单字符串
对象
订单
支付参数

需要专业的网站建设服务?

联系我们获取免费的网站建设咨询和方案报价,让我们帮助您实现业务目标

立即咨询