当前位置:网站首页>微信小程序路由再次跳转不触发onload
微信小程序路由再次跳转不触发onload
2022-07-05 06:23:00 【Heerey525】
情况:
1、从index页面跳转(wx.navigateTo)到add页面,第一次会进入add页面onLoad,但是第二次从index页面跳转(wx.navigateTo)到add页面,则不会进入add页面的onLoad;
2、从add页面跳转(wx.redirectTo)到index页面,不会进入index页面onLoad
原因:
在首次进入一个页面的时候,会进入该页面的onLoad,但是跳来跳去,其实路由并没有销毁,该页面已经存在路由栈,所以被缓存起来,并不会再次进入onLoad
解决方法:
1、在onShow中进入取路由参数
onShow: function () {
// 获取当前小程序的页面栈
let pages = getCurrentPages();
// 数组中索引最大的页面--当前页面
let currentPage = pages[pages.length-1];
// 打印出当前页面中的 options
console.log(currentPage.options)
}
2、switchTab的success回调中添加onLoad方法
wx.switchTab({
url: '../index/index',
success: function(e) {
var page = getCurrentPages().pop();
if (page == undefined || page == null) return;
page.onLoad();
}
})
参考资料:
小程序框架 /逻辑层 /页面路由
小程序使用 wx.navigateTo跳转到到页面,页面中的onload不执行?
微信小程序 switchTab跳转后新页面 onload 不触发的问题
边栏推荐
- 阿里新成员「瓴羊」正式亮相,由阿里副总裁朋新宇带队,集结多个核心部门技术团队
- Winter vacation water test 1 Summary
- June 29, 2022 daily
- 2022-5-第四周日报
- Game theory acwing 894 Split Nim game
- SQL三种连接:内连接、外连接、交叉连接
- AE tutorial - path growth animation
- How to set the drop-down arrow in the spinner- How to set dropdown arrow in spinner?
- Leetcode-22: bracket generation
- Operator priority, one catch, no doubt
猜你喜欢
随机推荐
AE tutorial - path growth animation
Game theory acwing 894 Split Nim game
论文阅读报告
Dataframe (1): introduction and creation of dataframe
容斥原理 AcWing 890. 能被整除的数
如何正确在CSDN问答进行提问
Leetcode-31: next spread
Design specification for mobile folding screen
1.15 - input and output system
Doing SQL performance optimization is really eye-catching
博弈论 AcWing 894. 拆分-Nim游戏
Applicable to Net free barcode API [off] - free barcode API for NET [closed]
博弈论 AcWing 892. 台阶-Nim游戏
求组合数 AcWing 887. 求组合数 III
Record the process of configuring nccl and horovod in these two days (original)
求组合数 AcWing 888. 求组合数 IV
Records of some tools 2022
2048 project realization
Modnet matting model reproduction
Winter messenger 2







