当前位置:网站首页>微信小程序路由再次跳轉不觸發onload
微信小程序路由再次跳轉不觸發onload
2022-07-05 06:26: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 不觸發的問題
边栏推荐
- MySQL advanced part 2: the use of indexes
- Leetcode heap correlation
- 博弈论 AcWing 893. 集合-Nim游戏
- Inclusion exclusion principle acwing 890 Divisible number
- Gauss Cancellation acwing 884. Solution d'un système d'équations Xor linéaires par élimination gaussienne
- MySQL advanced part 2: MySQL architecture
- 2.Oracle-数据文件的添加及管理
- Leetcode-556: the next larger element III
- [learning] database: MySQL query conditions have functions that lead to index failure. Establish functional indexes
- our solution
猜你喜欢

Idea debug failed

Gauss Cancellation acwing 884. Solution d'un système d'équations Xor linéaires par élimination gaussienne

安装OpenCV--conda建立虚拟环境并在jupyter中添加此环境的kernel

Is it impossible for lamda to wake up?

容斥原理 AcWing 890. 能被整除的数
![[2021]GIRAFFE: Representing Scenes as Compositional Generative Neural Feature Fields](/img/65/7fa32cd0005ddaaebacd85c25e0c7e.jpg)
[2021]GIRAFFE: Representing Scenes as Compositional Generative Neural Feature Fields

1.手动创建Oracle数据库

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

Chapter 6 relational database theory

Leetcode stack related
随机推荐
[leetcode] day94 reshape matrix
ADG5412FBRUZ-RL7应用 双电源模拟开关和多路复用器IC
5. Oracle TABLESPACE
【LeetCode】Easy | 20. Valid parentheses
高斯消元 AcWing 884. 高斯消元解异或線性方程組
MySQL advanced part 1: stored procedures and functions
1.14 - assembly line
FFmpeg build下载(包含old version)
什么是套接字?Socket基本介绍
Nested method, calculation attribute is not applicable, use methods
Leetcode backtracking method
Traversal of leetcode tree
Filter the numbers and pick out even numbers from several numbers
How to understand the definition of sequence limit?
求组合数 AcWing 889. 满足条件的01序列
Game theory acwing 893 Set Nim game
P3265 [jloi2015] equipment purchase
Game theory acwing 892 Steps Nim game
Single chip computer engineering experience - layered idea
Leetcode array operation