In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces the relevant knowledge of "how to solve the problem of global variable cache in the development of WeChat Mini Programs". The editor shows you the operation process through an actual case, and the operation method is simple, fast and practical. I hope this article "how to solve the problem of global variable cache in WeChat Mini Programs development" can help you solve the problem.
This problem arises because, in the event of input, I did not find a better way to monitor keyboard withdrawal, and it is also for a better user experience, so the problem comes with global variables. After assigning values, the user exits the page, and the global variable is cached by Wechat, which results in a bug that fails to change the mobile phone number after the user typed it once.
Let Btel ='', / / prevent users from maliciously modifying the mobile phone number Byzm =''; handleTel (e) {/ / modify the mobile phone number entered by the user this.setData ({tel:e.detail.value})}, handleYzm (e) {this.setData ({Yzm:e.detail.value}) Byzm = e.detail.value Let psd = this.data.psd, yzm = this.data.Yzm; yzm = = psd? This.setData ({isYzm:0}):';}, handleGetYzm () {let reg = common.telReg, val = this.data.tel If (! reg.test (val)) {wx.showModal ({content:', please enter the correct mobile phone number', showCancel:false, confirmColor:'#3cc51f' / / default is # 3cc51f success:res = > {if (res.confirm) {this.setData ({tel:''})}) } else {/ / use the global variable's mobile number Btel = val when sending CAPTCHA / / here is the global mobile number this.setData ({isReset: true, isNoClick: true}) const data = {global variable passed by tel:val//}; utils.sendRequest (api.YanZhengMa, data, this.handleGetYzmSucc.bind (this)) / / button timer let time = setInterval () = > {let phoneCode = this.data.time PhoneCode-- this.setData ({time: phoneCode}) if (phoneCode = = 0) {clearInterval (time) this.setData ({isReset: false, isNoClick: false Time:60})}, 1000)}}, / / then this step is to verify whether the user has modified the phone after requesting the CAPTCHA interface, and then save handleSave () {let name = this.data.name TelNum = this.data.tel, yzm = Byzm, status = this.data.isYzm, card = wx.getStorageSync ('UserCard') Let timestamp= new Date () .getTime (); if (yzm = =') {wx.showModal ({content:' Please enter the CAPTCHA.', showCancel:false, confirmColor:'#3cc51f'}) return false } if (nameplate verification, please retrieve the verification code again) {if (Btel! = telNum) {utils.showModal ('mobile phone number has changed, please get the CAPTCHA again.) } 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.showModal ('Please fill in the full information')}, / / then after the save is successful, the user clicks OK to clear the global variable can also clear the global variable during the hidden and unloaded life cycle. HandleSaveTel (res) {if (res.data.error = = 0) {let go = this.data.go, id = res.data.data.id, lv = res.data.data.level Wx.showModal ({content:' bind successfully ~', showCancel:false, confirmColor:'#3cc51f',// default is # 3cc51f success:res = > {if (res.confirm) {Byzm ='' / / A clean up of Mini Program global variable cache if (go) {wx.redirectTo ({url:'/ pages/user/cash/cash'})} else { If (id! = 0) {let card = wx.getStorageSync ('UserCard') Card.distribution_id = id; card.distribution_level = lv; wx.setStorageSync ('UserCard',card) Wx.setStorageSync ('seller' True)} wx.switchTab ({url:'/ pages/user/index'})} }) return false} else {utils.showModal (res.data.err_msg) }} this is the end of the content on "how to solve the problem of global variable caching in WeChat Mini Programs's development". Thank you for your reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.
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.