当前位置:网站首页>微信小程序路由再次跳转不触发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 不触发的问题
边栏推荐
- Basic explanation of typescript
- [wustctf2020] plain_ WP
- Chinese remainder theorem acwing 204 Strange way of expressing integers
- Operator priority, one catch, no doubt
- Leetcode-31: next spread
- MySQL advanced part 2: storage engine
- 2021apmcm post game Summary - edge detection
- 2022-5-the fourth week daily
- our solution
- Install opencv -- CONDA to establish a virtual environment and add the kernel of this environment in jupyter
猜你喜欢

What is socket? Basic introduction to socket

Paper reading report

Redis publish subscribe command line implementation

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

什么是套接字?Socket基本介绍

ollvm编译出现的问题纪录

将webApp或者H5页面打包成App

【LeetCode】Easy | 20. Valid parentheses

Quickly use Amazon memorydb and build your own redis memory database

Game theory acwing 891 Nim games
随机推荐
5. Oracle tablespace
1.手动创建Oracle数据库
__ builtin_ Popcount() counts the number of 1s, which are commonly used in bit operations
LeetCode-61
Real time clock (RTC)
容斥原理 AcWing 890. 能被整除的数
Redis publish subscribe command line implementation
Leetcode-6109: number of people who know secrets
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
Daily question 1189 Maximum number of "balloons"
Gauss Cancellation acwing 884. Solution d'un système d'équations Xor linéaires par élimination gaussienne
2048 project realization
Leetcode-22: bracket generation
Game theory acwing 891 Nim games
In depth analysis of for (VaR I = 0; I < 5; i++) {settimeout (() => console.log (I), 1000)}
Alibaba's new member "Lingyang" officially appeared, led by Peng Xinyu, Alibaba's vice president, and assembled a number of core department technical teams
There are three kinds of SQL connections: internal connection, external connection and cross connection
MySQL advanced part 2: MySQL architecture
3. Oracle control file management
【LeetCode】Day94-重塑矩阵