js
//发送验证码
sendcode:function(){
let that=this;
// 生成当前时间戳
var timestamp=Date.parse(new Date());
let time=wx.getStorageSync('time');
if(timestamp>time){
let phone =this.data.phone;
wx.request({
url: 'http://www.zc.com/code', //仅为示例,并非真实的接口地址
data: {phone},
method:"GET",
success (res) {
//第一次请求接口成功,存入两分钟后的时间戳,
wx.setStorageSync('time', timestamp+120000)
that.setData({
code:res.data
})
}
})
}else{
wx.showToast({
title: '恶意访问',
})
}
},