微信小程序 onShow) 事件
onShow) 事件不接受参数,因此无法获取页面 url 传递过来的参数,只有 onLoad) 事件可以。
onShowoptions){
console.logoptions) //打印值为 undefined
}
onLoadoptions){
console.logoptions) //正常打印出 options 值
}
解决方法——通过小程序页面栈获取
思路:
1.获取当前小程序的页面栈—数组 长度最大是10个页面。
2.数组中索引最大的页面就是当前页面,其中可以获取到 options 属性。
onShow) {
// 获取当前小程序的页面栈
let pages = getCurrentPages);
// 数组中索引最大的页面--当前页面
let currentPage = pages[pages.length-1];
// 打印出当前页面中的 options
console.logcurrentPage.options) //正常打印出 options 值
},
完结~