uni-app request回调函数内无法使用this.
找到一位博主写的解决方案 ,在此谢过 我的代码如下
/* uni.setStorageSync("phoneNumber",this.phoneNumber); console.log(uni.getStorageSync("phoneNumber"),this.phoneNumber) return; */ var _this = this; uni.request({ url:this.preUrl+App.User.GetCheckCode, method:"POST", header: { content-type: application/x-www-form-urlencoded }, data:{ phoneNumber : this.phoneNumber }, success(res) { console.log(res); var data = res.data; if(data.ret == 200){ if(data.data.res == OK){ uni.setStorageSync("checkCode",data.data.code); uni.setStorageSync("username",_this.phoneNumber); console.log(uni.getStorageSync("checkCode"),uni.getStorageSync("username")); //验证码发送成功后 获取按钮置灰 开始倒计时 60秒后可重新获取 _this.showText = true; _this.second = 60; var interval = setInterval(() => { --_this.second }, 1000) setTimeout(() => { clearInterval(interval) _this.showText = false }, 60000) console.log(_this.showText); }else{ console.log(发送验证码失败,res.data.res) } }else{ console.log(服务器异常) } }, fail(error) { console.log(error) } }) //把里面的值传回去 this.showText = _this.showText
上一篇:
uniapp开发微信小程序-2.页面制作
下一篇:
3个方案,绕过微信小程序官方审核