当前位置:网站首页>微信小程序路由再次跳轉不觸發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 不觸發的問題
边栏推荐
- Filter the numbers and pick out even numbers from several numbers
- P2575 master fight
- NotImplementedError: Cannot convert a symbolic Tensor (yolo_boxes_0/meshgrid/Size_1:0) to a numpy ar
- 高斯消元 AcWing 884. 高斯消元解异或線性方程組
- 博弈论 AcWing 892. 台阶-Nim游戏
- Traversal of leetcode tree
- 【LeetCode】Day94-重塑矩阵
- 4. Oracle redo log file management
- Leetcode-6108: decrypt messages
- Leetcode divide and conquer / dichotomy
猜你喜欢
MySQL advanced part 2: optimizing SQL steps
Network security skills competition in Secondary Vocational Schools -- a tutorial article on middleware penetration testing in Guangxi regional competition
AE tutorial - path growth animation
LeetCode-54
Leetcode array operation
Game theory acwing 894 Split Nim game
Day 2 document
2.Oracle-数据文件的添加及管理
博弈论 AcWing 894. 拆分-Nim游戏
Leetcode-6111: spiral matrix IV
随机推荐
区间问题 AcWing 906. 区间分组
5.Oracle-錶空間
How to understand the definition of sequence limit?
New title of module a of "PanYun Cup" secondary vocational network security skills competition
Network security skills competition in Secondary Vocational Schools -- a tutorial article on middleware penetration testing in Guangxi regional competition
Install opencv -- CONDA to establish a virtual environment and add the kernel of this environment in jupyter
Daily question 1189 Maximum number of "balloons"
RecyclerView的应用
Leetcode-6109: number of people who know secrets
Interval problem acwing 906 Interval grouping
Basic explanation of typescript
Leetcode heap correlation
MySQL advanced part 1: View
4. Oracle redo log file management
One question per day 1020 Number of enclaves
LeetCode 0108. Convert an ordered array into a binary search tree - the median of the array is the root, and the left and right of the median are the left and right subtrees respectively
MySQL advanced part 2: SQL optimization
What's wrong with this paragraph that doesn't work? (unresolved)
Game theory acwing 891 Nim games
论文阅读报告