当前位置:网站首页>微信小程序路由再次跳转不触发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 不触发的问题
边栏推荐
- 2022-5-the fourth week daily
- 博弈论 AcWing 893. 集合-Nim游戏
- 高斯消元 AcWing 884. 高斯消元解异或线性方程组
- Find the combination number acwing 889 01 sequence meeting conditions
- Modnet matting model reproduction
- How to set the drop-down arrow in the spinner- How to set dropdown arrow in spinner?
- Sword finger offer II 058: schedule
- Winter vacation water test 1 Summary
- Dataframe (1): introduction and creation of dataframe
- Single chip computer engineering experience - layered idea
猜你喜欢

Sorting out the latest Android interview points in 2022 to help you easily win the offer - attached is the summary of Android intermediate and advanced interview questions in 2022

高斯消元 AcWing 884. 高斯消元解异或線性方程組

Leetcode-6108: decrypt messages

Leetcode-6111: spiral matrix IV

4.Oracle-重做日志文件管理

背包问题 AcWing 9. 分组背包问题

International Open Source firmware Foundation (osff) organization

Install opencv -- CONDA to establish a virtual environment and add the kernel of this environment in jupyter

Leetcode array operation

5. Oracle tablespace
随机推荐
WordPress switches the page, and the domain name changes back to the IP address
What's wrong with this paragraph that doesn't work? (unresolved)
博弈论 AcWing 891. Nim游戏
One question per day 1020 Number of enclaves
Paper reading report
RecyclerView的应用
5.Oracle-錶空間
Alibaba established the enterprise digital intelligence service company "Lingyang" to focus on enterprise digital growth
New title of module a of "PanYun Cup" secondary vocational network security skills competition
Nested method, calculation attribute is not applicable, use methods
Single chip computer engineering experience - layered idea
Ffmpeg build download (including old version)
Leetcode-9: palindromes
Leetcode stack related
Sorting out the latest Android interview points in 2022 to help you easily win the offer - attached is the summary of Android intermediate and advanced interview questions in 2022
容斥原理 AcWing 890. 能被整除的数
How to generate an image from text on fly at runtime
阿里新成员「瓴羊」正式亮相,由阿里副总裁朋新宇带队,集结多个核心部门技术团队
在新线程中使用Handler
求组合数 AcWing 889. 满足条件的01序列