当前位置:网站首页>微信小程序路由再次跳轉不觸發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 不觸發的問題
边栏推荐
- Idea debug failed
- 安装OpenCV--conda建立虚拟环境并在jupyter中添加此环境的kernel
- What is socket? Basic introduction to socket
- Stack acwing 3302 Expression evaluation
- Find the combination number acwing 889 01 sequence meeting conditions
- MySQL advanced part 2: the use of indexes
- [2021]IBRNet: Learning Multi-View Image-Based Rendering Qianqian
- 博弈论 AcWing 891. Nim游戏
- Sum of three terms (construction)
- How to make water ripple effect? This wave of water ripple effect pulls full of retro feeling
猜你喜欢
Series of how MySQL works (VIII) 14 figures explain the atomicity of MySQL transactions and the principle of undo logging
3.Oracle-控制文件的管理
1.15 - input and output system
阿里新成员「瓴羊」正式亮相,由阿里副总裁朋新宇带队,集结多个核心部门技术团队
confidential! Netease employee data analysis internal training course, white whoring! (attach a data package worth 399 yuan)
International Open Source firmware Foundation (osff) organization
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
5. Oracle tablespace
MySQL advanced part 1: index
Stack acwing 3302 Expression evaluation
随机推荐
Dataframe (1): introduction and creation of dataframe
Leetcode-556: the next larger element III
How to generate an image from text on fly at runtime
TCP's understanding of three handshakes and four waves
How to set the drop-down arrow in the spinner- How to set dropdown arrow in spinner?
P2575 master fight
1.15 - input and output system
MySQL advanced part 1: stored procedures and functions
Leetcode-6111: spiral matrix IV
2048项目实现
安装OpenCV--conda建立虚拟环境并在jupyter中添加此环境的kernel
ADG5412FBRUZ-RL7应用 双电源模拟开关和多路复用器IC
MySQL advanced part 2: MySQL architecture
20220213-CTF MISC-a_ good_ Idea (use of stegsolve tool) -2017_ Dating_ in_ Singapore
2048 project realization
Leetcode divide and conquer / dichotomy
Niu Mei's math problems
[learning] database: several cases of index failure
Leetcode array operation
Find the combination number acwing 889 01 sequence meeting conditions