当前位置:网站首页>uni-app和微信小程序中的getCurrentPages()
uni-app和微信小程序中的getCurrentPages()
2022-04-23 08:17:00 【小小小,小可爱】
getCurrentPages() 函数用于获取当前页面栈的实例,以数组形式按栈的顺序给出,第一个元素为首页,最后一个元素为当前页面。
注意: getCurrentPages()仅用于展示页面栈的情况,请勿修改页面栈,以免造成页面状态错误。
uniapp官方文档:https://uniapp.dcloud.io/api/window/window.html#getcurrentpages
小程序官方文档:https://developers.weixin.qq.com/miniprogram/dev/reference/api/getCurrentPages.html
具体的方法介绍官方文档已经给了详细的说明 这里只介绍使用的实例
1.判断当前页面是不是进入app 或者小程序的第一个页面 ,典型的场景就是小程序的分享页,给用户分享的详情页面无法返回到首页,而是直接退出小程序
const pages = getCurrentPages();
if(pages.length == 1){
console.log("当前页面是进入小程序/app的第一个页面,可在此处做逻辑处理")
}
2.跨页面赋值 可以在当前页面修改上一个页面的值
let pages = getCurrentPages();//当前页面栈
if(pages.length>0){
let prevPage = pages[pages.length - 2];//上一页面
prevPage.setData({
//直接给上一个页面赋值
});
}
3.跳转页面的时候,刷新之前已经存在的页面,举个例子 ,当切换多语言之后刷新小程序或者app来更新语言文本就需要用到这个
uni.switchTab({
url: '/pages/tab/home',
success: function (e) {
var page = getCurrentPages().pop(); //当前页面
if (page == undefined || page == null) return;
page.onLoad(); //页面存在刷新当前页面 或者其它操作
}
})
4.获取当前页面相关信息
let pages = getCurrentPages(); //当前页面栈
//当前页面为页面栈的最后一个元素
let prevPage = pages[pages.length - 1];//当前页面
// pop() 方法用于删除并返回数组的最后一个元素 或者用此方法获取当前页面
// let prevPage = pages.pop();//当前页面
console.log( prevPage.route) //打印当前页面路径信息:输出为‘pages/tab/home’
版权声明
本文为[小小小,小可爱]所创,转载请带上原文链接,感谢
https://blog.csdn.net/weixin_47873655/article/details/124338617
边栏推荐
- 数据可视化:使用Excel制作雷达图
- Situational leaders - Chapter 7, solving performance problems
- Shell脚本进阶
- One click cleanup of pycharm and jupyter cache files under the project
- 分组背包呀
- 00后最关注的职业:公务员排第二,第一是?
- Queue (C language / linked list)
- An example of network communication based on TCP / IP protocol -- file transmission
- Word plus watermark
- Enctype attribute in form
猜你喜欢
ATSS(CVPR2020)
Campus transfer second-hand market source code download
RPC procedure
Harbor企业级镜像管理系统实战
RPC过程
RCC introduction of Hal Library
JVM工具之Arthas使用
My heart's broken! A woman's circle of friends envied others for paying wages on time and was fired. Even her colleagues who liked her were fired together
excle加水印
引用传递1
随机推荐
什么是RPC
洋桃电子STM32物联网入门30步笔记三、新建CubeIDE工程和设置讲解
freertos学习02-队列 stream buffer message buffer
请问中衍期货安全靠谱吗?
[explanation] get ora-12838: cannot read / modify an object after modifying it in parallel
form中enctype属性
ELK生产实践
Harbor企业级镜像管理系统实战
数据可视化:使用Excel制作雷达图
分布式消息中间件框架选型-数字化架构设计(7)
AQS & ReentrantLock 实现原理
洋桃电子STM32物联网入门30步笔记三、CubeMX图形化编程、设置开发板上的IO口
QT reading and writing XML files
'恶霸' Oracle 又放大招,各大企业连夜删除 JDK。。。
RCC introduction of Hal Library
Overview of bus structure
QT reads all files under the path or files of the specified type (including recursion, judging whether it is empty and creating the path)
Knowledge points and problem solutions related to information collection
Shell脚本进阶
DJ音乐管理软件Pioneer DJ rekordbox