In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-20 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces "what are the methods for returning to the previous page with Mini programs". In daily operation, I believe many people have doubts about what are the problems in the methods for returning to the previous page with small programs. The editor has consulted all kinds of materials and sorted out simple and easy operation methods. I hope to help you answer the doubts about "what are the methods for returning to the previous page with small programs"! Next, please follow the small series to learn together!
The page jump API of Mini programs, such as wx.navigateTo() and wx.redirectTo(), jump to a brand-new page. When this page is a form, sometimes you need to jump to other pages to select information and then jump back. The information filled in before must exist. At this time, you can jump to the page of information selection, select the information and set the data on the previous page, and then return to the previous page. In this way, the data will exist.
方法一
把当前页面数据放入本地缓存( wx.setStorage(wx.setStorageSync),上一个页面再从缓存中取出(wx.getStorage(wx.getStorageSync))同时退出登录时要清除缓存(wx.clearStorage(wx.clearStorageSync))。
方法二
在当前页设置上一页的data,例如var pages = getCurrentPages(); // 获取页面栈var currPage = pages[pages.length - 1]; // 当前页面var prevPage = pages[pages.length - 2]; // 上一个页面prevPage.setData({mydata: {a:1, b:2} // 假数据})当然这个"mydata"必须是上一页有的数据才行
返回上一页的数据为:
wx.navigateBack({delta: 1})2、直接调用方法名来更新数据 页面A
Page({data: {name: ''},...,//更新namechangeData: function(name){this.setData({name: name})}})页面B,假设有一个文本框用于输入姓名,点击返回按钮后更新页面A的name
Page({//此方法用于文本框输入回调inputTyping: function (e) {//获取页面栈var pages = getCurrentPages();if(pages.length > 1){//上一个页面实例对象var prePage = pages[pages.length - 2];//关键在这里prePage.changeData(e.detail.value)}}})这样就可以实现数据传递给上一个页面,要注意页面A必须使用wx.navigateTo跳转到页面B,不能使用wx.redirectTo,这样会关闭上一个页面,导致页面B无法获取上一页Page实例。
方法三 在app.js中设置全局变量,当前页赋值,上一页取之
方法为
globalData: {userInfo: null,}注意:方法一,方法三,都需要重新刷新页面数据所走方法为:
/*** 生命周期函数--监听页面显示*/onShow: function () { },到此,关于"小程序带参返回上一页的方法有哪些 "的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注网站,小编会继续努力为大家带来更多实用的文章!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.