当前位置:网站首页>微信小程序路由再次跳转不触发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 不触发的问题
边栏推荐
- C job interview - casting and comparing - C job interview - casting and comparing
- Design specification for mobile folding screen
- June 29, 2022 daily
- 4. Oracle redo log file management
- 2022/6/29-日报
- Sword finger offer II 058: schedule
- 安装OpenCV--conda建立虚拟环境并在jupyter中添加此环境的kernel
- Client use of Argo CD installation
- Alibaba established the enterprise digital intelligence service company "Lingyang" to focus on enterprise digital growth
- Network security skills competition in Secondary Vocational Schools -- a tutorial article on middleware penetration testing in Guangxi regional competition
猜你喜欢

Redis-01.初识Redis

Find the combination number acwing 889 01 sequence meeting conditions

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

Interval problem acwing 906 Interval grouping

Find the combination number acwing 888 Find the combination number IV

Chapter 6 relational database theory

求组合数 AcWing 889. 满足条件的01序列

Network security skills competition in Secondary Vocational Schools -- a tutorial article on middleware penetration testing in Guangxi regional competition

区间问题 AcWing 906. 区间分组

博弈论 AcWing 894. 拆分-Nim游戏
随机推荐
阿里巴巴成立企业数智服务公司“瓴羊”,聚焦企业数字化增长
LeetCode-54
June 29, 2022 daily
[wustctf2020] plain_ WP
[leetcode] day94 reshape matrix
2048项目实现
How to understand the definition of sequence limit?
博弈论 AcWing 893. 集合-Nim游戏
MySQL advanced part 1: index
博弈论 AcWing 892. 台阶-Nim游戏
Chinese remainder theorem acwing 204 Strange way of expressing integers
2022/6/29-日报
Redis-02.Redis命令
[moviepy] unable to find a solution for exe
P3265 [jloi2015] equipment purchase
5. Oracle TABLESPACE
MySQL advanced part 1: triggers
Gauss Cancellation acwing 884. Solution d'un système d'équations Xor linéaires par élimination gaussienne
20220213-CTF MISC-a_ good_ Idea (use of stegsolve tool) -2017_ Dating_ in_ Singapore
背包问题 AcWing 9. 分组背包问题