当前位置:网站首页>微信小程序路由再次跳转不触发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 不触发的问题
边栏推荐
- Is it impossible for lamda to wake up?
- 博弈论 AcWing 892. 台阶-Nim游戏
- Leetcode-9: palindromes
- Nested method, calculation attribute is not applicable, use methods
- Winter messenger 2
- 容斥原理 AcWing 890. 能被整除的数
- 11-gorm-v2-02-create data
- How to make water ripple effect? This wave of water ripple effect pulls full of retro feeling
- Stack acwing 3302 Expression evaluation
- Leetcode-6108: decrypt messages
猜你喜欢

【高德地图POI踩坑】AMap.PlaceSearch无法使用

Bash exercise 17 writing scripts to install the server side of FRP reverse proxy software

5. Oracle tablespace
![[moviepy] unable to find a solution for exe](/img/0a/4841f53cedc1333654b9443e406f4c.jpg)
[moviepy] unable to find a solution for exe

Interval problem acwing 906 Interval grouping

5.Oracle-錶空間

4. Oracle redo log file management

LeetCode-54

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

MySQL advanced part 1: index
随机推荐
International Open Source firmware Foundation (osff) organization
Operator priority, one catch, no doubt
Chapter 6 relational database theory
TypeScript 基础讲解
1.手动创建Oracle数据库
[2021]IBRNet: Learning Multi-View Image-Based Rendering Qianqian
1.13 - RISC/CISC
MySQL advanced part 2: SQL optimization
LeetCode 1200. Minimum absolute difference
4. Oracle redo log file management
Bit of MySQL_ OR、BIT_ Count function
5.Oracle-表空间
3.Oracle-控制文件的管理
Records of some tools 2022
How to make water ripple effect? This wave of water ripple effect pulls full of retro feeling
中国剩余定理 AcWing 204. 表达整数的奇怪方式
5. Oracle TABLESPACE
Nested method, calculation attribute is not applicable, use methods
Leetcode-22: bracket generation
Regulations for network security events of vocational group in 2022 Guizhou Vocational College skill competition