关注分享主机优惠活动
国内外VPS云服务器

处理微信小程序开发中的全局变量缓存问题(文件用于全局配置微信小程序)

出现这个问题是因为,在输入的事件中,我没有找到更好的方法来监控键盘回缩,也是为了更好的用户体验,所以产生的问题就是全局变量。赋值后用户退出此页面,全局变量被微信缓存,随后造成用户输入一次后修改手机号失败的bug。

处理微信小程序开发中的全局变量缓存问题(文件用于全局配置微信小程序)-主机频道

让Btel = & # 039',//防止用户恶意修改手机号码Byzm = & # 039';HandleTel(e) {//这里修改用户输入的手机号码this . setdata({ tel:e . detail . value })},handleYzm(e){ this . setdata({ Yzm:e . detail . value })Byzm = e . detail . value;设psd = this.data.psd,yzm = this . data . yzm;yzm == psd?this . setdata({ isYzm:0 }):& # 039;';},handleGetYzm(){ let reg = common . telreg,val = this . data . tel;如果(!reg . test(val)){ wx . show modal({ content:& # 039;请输入正确的手机号码& # 039;,showCancel:false,confirm color:& # 039;# 3cc51f & # 039,//默认值为# 3c c51f success:RES = >;{ if(RES . confirm){ this . setdata({ tel:& # 039;'} } } } } } else {//发送验证码时使用全局变量Btel = val的手机号码;//这里是全局手机号this.setdata ({isreset: true,isno click:true })constdata = { tel:val//是全局变量};utils.sendRequest(api。YanZhengMa,data,this . handlegetyzmsucc . bind(this));//button timer let time = setinterval(()= >;{ let phone code = this . data . time;phone code --this . setdata({ time:phone code })if(phone code = = 0){ clear interval(time)this . setdata({ is reset:false,isNoClick: false,time:60 }) } },000)}},//那么这个步骤就是检查用户在请求验证码接口后是否修改了手机然后保存handle save(){ let name = this . data . name,telNum = this.data.tel,yzm = this . data . isyzm用户卡& # 039;);设时间戳=新日期()。getTime();if(yzm = = & # 039;'){ wx . show modal({ content:& # 039;请输入验证码。',showCancel:false,confirm color:& # 039;# 3cc51f & # 039})返回false}如果(名字!=''& amp& amptelNum!=''){ if(Btel!= telNum){ utils . show modal(& # 039;手机号已更改,请重新获取验证码。');} else { const data = { distribution _ id:card . distribution _ id,post:{ user_name:name,user_tel:Btel,user_code:yzm },user_id:card.user_id,password:yzm+timestamp };utils.sendRequest(api。BindTel,data,this . handlesavetel . bind(this));} } else { utils . show modal(& # 039;请填写完整的信息& # 039;);}},//然后保存成功后,用户点击确定清除全局变量,也可以在隐藏卸载的生命周期中清除。handleSaveTel(RES){ if(RES . data . error = = 0){ let go = this . data . go,id = res.data.data.id,LV = RES . data . data . level;wx . show modal({ content:& # 039;绑定成功~ & # 039;,showCancel:false,confirm color:& # 039;# 3cc51f & # 039,//默认值为# 3c c51f success:RES = >;{ if(RES . confirm){ Byzm = & # 039;';//清除applet全局变量缓存if(go){ wx . redirect to({ URL:& # 039;/页面/用户/现金/现金& # 039;}) }else { if (id!= 0){ let card = wx . getstoragesync(& # 039;用户卡& # 039;);card.distribution _ id = idcard.distribution_level =吕;wx . setstoragesync(& # 039;用户卡& # 039;,卡);wx . setstoragesync(& # 039;卖家& # 039;,true)} wx . switch tab({ URL:& # 039;/pages/user/index & # 039;})} } } } })return false } else { utils . show modal(RES . data . err _ msg);}}相信你看完这个案例已经掌握了方法。更多精彩请关注即时码站其他相关文章!

推荐阅读:

微信小程序开发中如何使用地图对象

如何实现微信小程序开发的上拉加载

未经允许不得转载:主机频道 » 处理微信小程序开发中的全局变量缓存问题(文件用于全局配置微信小程序)

评论 抢沙发

评论前必须登录!