当前位置:网站首页>微信小程序路由再次跳转不触发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 不触发的问题
边栏推荐
- 阿里新成员「瓴羊」正式亮相,由阿里副总裁朋新宇带队,集结多个核心部门技术团队
- MPLS experiment
- Network security skills competition in Secondary Vocational Schools -- a tutorial article on middleware penetration testing in Guangxi regional competition
- C Primer Plus Chapter 15 (bit operation)
- SQL三种连接:内连接、外连接、交叉连接
- __ builtin_ Popcount() counts the number of 1s, which are commonly used in bit operations
- [rust notes] 16 input and output (Part 2)
- Gauss Cancellation acwing 884. Solution d'un système d'équations Xor linéaires par élimination gaussienne
- 5.Oracle-表空间
- TypeScript 基础讲解
猜你喜欢
Chinese remainder theorem acwing 204 Strange way of expressing integers
1.手动创建Oracle数据库
Redis publish subscribe command line implementation
Game theory acwing 891 Nim games
P2575 master fight
Paper reading report
ollvm编译出现的问题纪录
There are three kinds of SQL connections: internal connection, external connection and cross connection
3. Oracle control file management
NotImplementedError: Cannot convert a symbolic Tensor (yolo_boxes_0/meshgrid/Size_1:0) to a numpy ar
随机推荐
Shutter web hardware keyboard monitoring
Redis-01.初识Redis
【LeetCode】Day95-有效的数独&矩阵置零
安装OpenCV--conda建立虚拟环境并在jupyter中添加此环境的kernel
Winter vacation water test 1 Summary
Gaussian elimination acwing 884 Gauss elimination for solving XOR linear equations
Bit of MySQL_ OR、BIT_ Count function
Redis-02.Redis命令
Leetcode heap correlation
1.15 - input and output system
4. Oracle redo log file management
MySQL advanced part 2: the use of indexes
【LeetCode】Easy | 20. Valid parentheses
1.手动创建Oracle数据库
Modnet matting model reproduction
【LeetCode】Day94-重塑矩阵
2022-5-the fourth week daily
Inclusion exclusion principle acwing 890 Divisible number
Series of how MySQL works (VIII) 14 figures explain the atomicity of MySQL transactions and the principle of undo logging
Alibaba established the enterprise digital intelligence service company "Lingyang" to focus on enterprise digital growth