请稍等 ...
×

采纳答案成功!

向帮助你的同学说点啥吧!感谢那些助人为乐的人

手机验证码倒数计时,怎么把改变的数据传到template里?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
var countdown = 60;
var settime = function (that) {
if (countdown == 0) {
that.setData({
is_show: true
})
countdown = 60;
return;
else {
that.setData({
is_show: false,
last_time: countdown
})
countdown--;
}
setTimeout(function () {
settime(that)
}
, 1000)
}
Page({
/**
  * 页面的初始数据
  */
data: {
is_show: "true"
},
getSmsTap: function () {
var that = this;
// 将获取验证码按钮隐藏60s,60s后再次显示
that.setData({
is_show: (!that.data.is_show)   //false
})
settime(that);
}
})


正在回答 回答被采纳积分+3

插入代码

4回答

提问者 xiaozheng 2017-10-28 08:53:10
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
var logisticsData = require('../../../data/logistics-data.js')
var inputContent = {}
var countdown = 60;
var settime = function (that) {
if (countdown == 0) {
that.setData({
is_show: true
})
countdown = 60;
return;
else {
that.setData({
is_show: false,
last_time: countdown
})
 
countdown--;
}
setTimeout(function () {
settime(that)
}
, 1000)
}
 
Page({
data: {
inputContent: {},
is_show: "true",
},
 
onLoad: function (options) {
this.setData({
sign_up_key: logisticsData.sign_up
})
},
 
inputBlur: function (e) {
inputContent[e.currentTarget.id] = e.detail.value
if ('phone' == e.currentTarget.id) {
var phone = inputContent[e.currentTarget.id];
var myreg = /^(((1[0-9]{1}))+\d{9})$/;
if (phone.length != 11 || !myreg.test(phone)) {
wx.showToast({
title: '手机号有误!',
icon: 'success',
duration: 1500
})
this.data.phone = 'fail'
else {
this.data.phone = phone
}
}
if ('userName' == e.currentTarget.id) {
var userName = inputContent[e.currentTarget.id];
if (userName.length >= 12 || userName.length <= 4) {
wx.showToast({
title: '用户名有误',
icon: 'success',
duration: 1500
})
this.data.userName = 'fail'
else {
this.data.userName = userName
}
}
if ('password' == e.currentTarget.id) {
var password = inputContent[e.currentTarget.id];
if (password.length >= 12 || password.length <= 5) {
wx.showToast({
title: '密码有误',
icon: 'success',
duration: 1500
})
this.data.password = 'fail'
else {
this.data.password = password
}
}
if ('passwordAgain' == e.currentTarget.id) {
var passwordAgain = inputContent[e.currentTarget.id];
if (passwordAgain != this.data.password) {
wx.showToast({
title: '两次密码不一致',
icon: 'success',
duration: 1500
})
this.data.passwordAgain = 'fail'
else {
this.data.passwordAgain = passwordAgain
}
}
if ('code' == e.currentTarget.id) {
var code = inputContent[e.currentTarget.id];
if (code.length !=6) {
wx.showToast({
title: '验证码6位数字',
icon: 'success',
duration: 1500
})
this.data.code = 'fail'
else {
this.data.code = code
}
}
},
 
agreementTap: function (event) {
wx.navigateTo({
url: "../agreement/agreement"
})
},
 
idTap: function (event) {
if (this.data.phone == 'fail' || this.data.phone == undefined) {
wx.showToast({
title: '手机号有误!',
icon: 'success',
duration: 1500
})
return false
}
if (this.data.userName == 'fail' || this.data.userName == undefined) {
wx.showToast({
title: '用户名有误',
icon: 'success',
duration: 1500
})
return false
}
 
if (this.data.password == 'fail' || this.data.password == undefined) {
wx.showToast({
title: '密码有误',
icon: 'success',
duration: 1500
})
return false
}
if (this.data.passwordAgain == 'fail' || this.data.passwordAgain == undefined) {
wx.showToast({
title: '两次密码不一致',
icon: 'success',
duration: 1500
})
return false
}
if (this.data.code == 'fail' || this.data.code == undefined) {
wx.showToast({
title: '验证码6位数字',
icon: 'success',
duration: 1500
})
return false
}
var that = this//不要漏了这句,很重要
wx.request({
method: 'POST',
url: getApp().data.domain + 'interface/wx/common/user/login',
url: getApp().data.domain + 'interface/wx/common/sms',
data: {
'appId''wxb3094e84f2642f59',
'phone'this.data.phone,
'password'this.data.password,
},
header: {
'content-type''application/x-www-form-urlencoded' // 默认值
},
success: function (res) {
console.log(res.data.code)
if (res.data.code == 1000) {
console.log(res.data.msg)
that.setData({
loginData: res.data.data,
})
else {
wx.showToast({
title: res.data.msg,
icon: 'success',
duration: 1500
})
}
 
}
})
},
getSmsTap: function () {
var that = this;
// 将获取验证码按钮隐藏60s,60s后再次显示
that.setData({
is_show: (!that.data.is_show) //false
})
settime(that);
}
 
// getSmsTap: function (event) {
//   console.log(this.data.phone)
//   var that = this//不要漏了这句,很重要
//   if (this.data.phone == 'fail' || this.data.phone == undefined) {
//     wx.showToast({
//       title: '手机号有误!',
//       icon: 'success',
//       duration: 1500
//     })
//     return false
//   }
//   wx.request({
//     method: 'POST',
//     url: getApp().data.domain + 'interface/wx/common/sms',
//     data: {
//       'appId': 'wxb3094e84f2642f59',
//       'phone': this.data.phone,
//       'type': '1',
//     },
//     header: {
//       'content-type': 'application/x-www-form-urlencoded' // 默认值
//     },
//     success: function (res) {
//       console.log(res.data.code)
//       if (res.data.code == 1000) {
//         console.log(res.data.msg)
//         that.setData({
//           loginData: res.data.data,
//         })
//       } else {
//         wx.showToast({
//           title: res.data.msg,
//           icon: 'success',
//           duration: 1500
//         })
//       }
 
//     }
//   })
// },
 
})


0 回复 有任何疑惑可以回复我~
提问者 xiaozheng 2017-10-27 21:09:52
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<import src="../../template/input/input-template.wxml" />
<view class="sign-up-container">
 
<view>
<block wx:for="{{sign_up_key}}" wx:for-item="input">
<template is="inputTemplate" data="{{...input,is_show}}" />
</block>
</view>
 
<view class="sign-up-agreement-container">
<text bindtap="agreementTap" class="sign-up-agreement-text">使用协议</text>
<image class="sign-up-arrow" src="../../../images/icon/arrow-right.png" />
<switch class="sign-up-switch" />
</view>
 
<text class="sign-phone-prompt">验证码不正确</text>
<button bindtap="idTap" class="sign-up-btn">下一步</button>
</view>


0 回复 有任何疑惑可以回复我~
提问者 xiaozheng 2017-10-27 20:59:29

这样是正常的,但是如何应用到template里去控制数据呢?

0 回复 有任何疑惑可以回复我~
提问者 xiaozheng 2017-10-27 20:55:16
1
2
3
4
<view>
<button class="{{is_show?'show':'hide'}}" bindtap="getSmsTap">获取验证码</button>
<button class="{{is_show?'hide':'show'}}">{{last_time}}</button>
</view>


0 回复 有任何疑惑可以回复我~
  • 7七月 #1
    传入数据 不就是data=么?有什么问题吗?
    回复 有任何疑惑可以回复我~ 2017-10-27 23:30:38
  • 提问者 xiaozheng 回复 7七月 #2
    我想控制btn的验证码倒计时,数字和获取验证码切换,但是失效了
    回复 有任何疑惑可以回复我~ 2017-10-28 08:54:44
  • 提问者 xiaozheng 回复 7七月 #3
    改变is_show的值失败
    回复 有任何疑惑可以回复我~ 2017-10-28 08:57:48
问题已解决,确定采纳
还有疑问,暂不采纳
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号