如何实现页面间传数据?

小程序 文章 2022-02-19 16:00 352 0 全屏看文

AI助手支持GPT4.0

如何实现页面间传数据?How to transfer data between pages?

如何实现页面间传数据?

点击购买之后需要将AppData中的proData传递到orders界面,我怎么写都提示undefined ,请问应该怎么解决?

After clicking purchase, you need to transfer the prodata in appdata to the orders interface. I will prompt undefined whatever I write. How can I solve it?

回答:

Larry:
wx.navigateTo({  url: '/pages/orders/orders?orderArr=' + this.data.proData)}
城市多少盏灯:这样也不行,我试过了
Larry:proData是个对象,应该要用eventChannel来传,或者转换成字符串
城市多少盏灯:已解决,感谢🙏
小黎:

 wx.navigateTo({

      url: '/pages/orders/orders?orderArr=' + JSON.stringify(this.data.proData),

    })

陈宇明:
首先你要拿到proDat对象,通过 this.data.proData 拿到后有四种方式传递1. 通过存储到数据缓存 https://developers.weixin.qq.com/miniprogram/dev/api/storage/wx.setStorageSync.html2. 通过App存放全局变量3. URL数据传递,这个对象的话需要先通过JSON.stringify(obj)将 object 对象转换为 JSON 字符串,并返回该字符串,再到接收页面JSON.parse解析。4. 通过事件通信通道 https://developers.weixin.qq.com/miniprogram/dev/apioute/EventChannel.html
城市多少盏灯:已解决感谢🙏
拾忆:

问题1:你代码里res并不是当前函数内返回的,所以获取不到值

问题2:url传参需要是传字符串,不能是对象、数组这种的

城市多少盏灯:已解决感谢🙏
城市多少盏灯:已解决感谢🙏

-EOF-

AI助手支持GPT4.0