我现在,有一个列表页,我要从列表,跳转到详情页。
而其实所有数据,列表页都有。
我想从列表页,直接全部带过去,不想重新id请求一次了。
用全局变量可以吗,感觉一般不会这样用,这样用有什么坏处吗
小程序不同页面之间,传递数据的问题?What is the problem of transferring data between different pages of the applet?
小程序不同页面之间,传递数据的问题?我现在,有一个列表页,我要从列表,跳转到详情页。
而其实所有数据,列表页都有。
我想从列表页,直接全部带过去,不想重新id请求一次了。
用全局变量可以吗,感觉一般不会这样用,这样用有什么坏处吗
Now, I have a list page. I want to jump from the list to the details page. In fact, all the data is available on the list page. I want to take all of them directly from the list page. I don't want to request ID again. Is it OK to use global variables? I don't think they are used in this way. Is there any harm in using them in this way
回答:
详情页没有通过id取, 想从列表传, 本身就不合理(如果详情页分享出去了呢...当然也可能没有这个业务场景)
你还怕啥全局变量的问题
wx.navigateTo({ url: '../detail/detail?list=' + encodeURIComponent(JSON.stringify(this.data.list))})// detail/detail.jsonLoad(options) { let list = options.list ? JSON.parse(ecodeURIComponent(options.list)): [] this.setData({ list })}
原文出处:小程序不同页面之间,传递数据的问题?
用变量没问题,也可以考虑给详情页传索引,然后通过页面栈的方式获取上一页的数据,直接在详情页显示对应的数据。
let prevPageData = getCurrentPages();let _data = prevPageData[prevPageData.length - 2].data;