微信公开课
微信公开课小程序热门讨论关于「页面之间数据传递」的小程序开发问题
补充:页面之间数据传递
展开:在appjs中定义一个全局变量赋值为空,然后在userjs中定义函数判断如果为空,wxredirectTo到logs页面,并在logs页面按钮中赋值全局变量,然后返回user页面,可是user的onload的函数中始终判断全局变量为空即速小程序:麻烦提供能复现问题的代码片段(https:developersweixinqqcomminiprogramdevdevtoolsminicodehtml):在手机上也调试了,问题一样是不是wxredirectTo把全局变量清空了appjsApp({***当小程序初始化完成时,会触发onLaunch(全局只触发一次)*onLaunch:function(){ },***当小程序启动,或从后台进入前台显示,会触发onShow*onShow:function(options){ },***当小程序从前台进入后台,会触发onHide*onHide:function(){ },***当小程序发生脚本错误,或者api调用失败时,会触发onError并带上错误信息*onError:function(msg){ },appData:{userInfo:null}})indexjsvarapp=getApp();Page({data:{text:这是一个页面},onLoad:function(options){页面初始化options为页面跳转所带来的参数},onReady:function(){页面渲染完成},onShow:function(){页面显示},onHide:function(){页面隐藏},onUnload:function(){页面关闭},login:function(){if(appappDatauserInfo==null){wxredirectTo({url:TestTest,})}}})logsjsvarapp=getApp();Page({data:{username:null,password:null,},onLoad:function(options){ },onReady:function(){ },onShow:function(){页面显示},onHide:function(){页面隐藏},onUnload:function(){页面关闭},loginBtnClick:function(){用户名和密码验证的过程appappDatauserinfo={username:thisdatausername,password:thisdatapassword};consolelog(appappDatauserinfousername);consolelog(appappDatauserinfopassword);wxredirectTo({url:TestTest})},usernameInput:function(event){ thissetData({username:eventdetailvalue})},passwordInput:function(event){thissetData({password:eventdetailvalue})}}):这个问题要不是赋值异步的问题,还有就是你用的是工具上的真机调试没有在手机上真机调试
更多有关「页面之间数据传递」的讨论可以前往微信公开课小程序参与互动哦!了解更多