小程序中当需要传递大量数据参数时,可以使用消息触发或监听,注意,不适合uniapp的h5,刷新会丢失数据
例如从A页面跳转到B页面
A页面
/** 查看日志 */
function toLog() {
uni.navigateTo({
url: "./gemLog",
success: res => {
let ad = [1, 2, 3]
let od = { key: "value" }
res.eventChannel.emit("acceptDataFromOpenerPage", { ad, od })
}
})
}
B页面
import { getCurrentInstance } from "vue"
const instance = getCurrentInstance().proxy
const eventChannel = instance.getOpenerEventChannel()
eventChannel.on("acceptDataFromOpenerPage", function (data: any) {
console.log("acceptDataFromOpenerPage", data)
})
/** 页面注销时候销毁 */
onUnload(() => {
eventChannel.off("acceptDataFromOpenerPage")
})
如果是微信小程序,替换uni为wx
打印信息截图