当前位置:网站首页>微信小程序路由再次跳转不触发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 不触发的问题
边栏推荐
- 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
- MySQL advanced part 1: stored procedures and functions
- 4. Object mapping Mapster
- Bit of MySQL_ OR、BIT_ Count function
- RecyclerView的应用
- What's wrong with this paragraph that doesn't work? (unresolved)
- Traversal of leetcode tree
- Leetcode backtracking method
- Game theory acwing 893 Set Nim game
- 高斯消元 AcWing 884. 高斯消元解异或線性方程組
猜你喜欢

【高德地图POI踩坑】AMap.PlaceSearch无法使用

Day 2 document

WordPress switches the page, and the domain name changes back to the IP address

5. Oracle TABLESPACE

1.13 - RISC/CISC

Alibaba established the enterprise digital intelligence service company "Lingyang" to focus on enterprise digital growth

Install opencv -- CONDA to establish a virtual environment and add the kernel of this environment in jupyter

3. Oracle control file management
![[2021]GIRAFFE: Representing Scenes as Compositional Generative Neural Feature Fields](/img/65/7fa32cd0005ddaaebacd85c25e0c7e.jpg)
[2021]GIRAFFE: Representing Scenes as Compositional Generative Neural Feature Fields

5. Oracle tablespace
随机推荐
在新线程中使用Handler
Inclusion exclusion principle acwing 890 Divisible number
[2020]GRAF: Generative Radiance Fields for 3D-Aware Image Synthesis
20220213-CTF MISC-a_ good_ Idea (use of stegsolve tool) -2017_ Dating_ in_ Singapore
7.Oracle-表结构
[wustctf2020] plain_ WP
论文阅读报告
博弈论 AcWing 892. 台阶-Nim游戏
[rust notes] 16 input and output (Part 2)
Single chip computer engineering experience - layered idea
[BMZCTF-pwn] ectf-2014 seddit
Nested method, calculation attribute is not applicable, use methods
Leetcode-556: the next larger element III
Usage scenarios of golang context
Chart. JS - Format Y axis - chart js - Formatting Y axis
11-gorm-v2-02-create data
MySQL advanced part 1: View
将webApp或者H5页面打包成App
NotImplementedError: Cannot convert a symbolic Tensor (yolo_boxes_0/meshgrid/Size_1:0) to a numpy ar
WordPress switches the page, and the domain name changes back to the IP address