小程序
小游戏
企业微信
微信支付
扫描小程序码分享
网络不好的时候,多次点击open-type getUserInfo 按钮,会导致该按钮事件执行多次。怎么解决呢
2 个回答
加粗
标红
插入代码
插入链接
插入图片
上传视频
bindGetUserInfo: function (e) {
console.log(e)
wx.showToast({
title: '点击了button',
icon: 'success',
duration: 2000
})
console.log("isclick=====bindGetUserInfo=======11111", isclick)
var that = this
console.log("userInfo===========")
console.log(that.data.userInfo)
// var token = userInfo.token
// var unionid = userInfo.user.unionid
var encryptedData = e.detail.encryptedData;
var iv = e.detail.iv;
var laravelsession = publicUrl.globalData.laravelsession;
var xsrftoken = publicUrl.globalData.xsrftoken;
var sys_token = publicUrl.globalData.sys_token;
if (e.detail.userInfo != undefined) {
console.log("isclick=======2222=", isclick)
if (!that.data.userInfo.user.nickname) {
if(isclick==true){
wx.request({
url: url + '/miniprogram/registeruser',
method: 'POST',
data: {
// unionid: unionid,
// token: token,
encryptedData: encryptedData,
iv: iv,
rawData: e.detail.rawData,
signature: e.detail.signature
//_token: sys_token
},
header: publicUrl.globalData.header,
success: function (res) {
console.log("注册用户成功==============")
console.log(res)
if (res.data.code == 0) {
isclick = false
console.log("code================0")
var laravelsession = res.header["Set-Cookie"].match(/laravel_session=(.*?);/)[1]
var xsrftoken = res.header["Set-Cookie"].match(/XSRF-TOKEN=(.*?);/)[1]
var sys_token = res.header["xxvv"]
publicUrl.globalData.laravelsession = laravelsession
publicUrl.globalData.xsrftoken = xsrftoken
publicUrl.globalData.sys_token = sys_token
var header = {
'Content-type': 'application/x-www-form-urlencoded',
'Cookie': 'XSRF-TOKEN=' + xsrftoken + '; ' + 'laravel_session=' + laravelsession,
'X-CSRF-TOKEN': sys_token,
'X-Requested-With': 'XMLHttpRequest',
'uf': '1'
}
publicUrl.globalData.header = header
that.setData({
userInfo: res.data.result
// userInfo = res.data.result
wx.setStorage({
key: "myuser",
data: res.data.result
publicUrl.globalData.userInfo = res.data.result
key: "userInfo",
if (that.data.sid) {
if (that.data.share == 1) {
wx.reLaunch({
url: '/pages/ranking/ranking?storeid=' + that.data.sid + '&share=1'
} else {
url: '/pages/ranking/ranking?storeid=' + that.data.sid
} else if (that.data.uunionid) {
url: '/pages/personal/personal?uunionid=' + that.data.uunionid + '&share=1'
url: '/pages/personal/personal?uunionid=' + that.data.uunionid
url: '/pages/city/city?source=login',
} else if (res.data.code == 5588) {
login(that)
console.log("code==============else=========", res.data.code)
fail: function (res) {
console.log("注册用户失败===============")
var userInfo = publicUrl.globalData.userInfo
var myuser = wx.getStorageSync('myuser');
console.log("您没有授权哦")
title: '您没有授权哦~',
icon: 'none',
你好,麻烦通过点击下方“反馈信息”按钮,提供出现问题的。
你自己写个事件节流。在getUserInfo绑定的事件里面。
根据取出的东西。如果取出来一遍之后。即使在点也不走接口
不太懂,,,,能说的详细点吗
在
这个样子
感谢
不客气,给个赞同就好了
关注后,可在微信内接收相应的重要提醒。
请使用微信扫描二维码关注 “微信开放社区” 公众号
bindGetUserInfo: function (e) {
console.log(e)
wx.showToast({
title: '点击了button',
icon: 'success',
duration: 2000
})
console.log("isclick=====bindGetUserInfo=======11111", isclick)
var that = this
console.log("userInfo===========")
console.log(that.data.userInfo)
// var token = userInfo.token
// var unionid = userInfo.user.unionid
var encryptedData = e.detail.encryptedData;
var iv = e.detail.iv;
var laravelsession = publicUrl.globalData.laravelsession;
var xsrftoken = publicUrl.globalData.xsrftoken;
var sys_token = publicUrl.globalData.sys_token;
if (e.detail.userInfo != undefined) {
console.log("isclick=======2222=", isclick)
if (!that.data.userInfo.user.nickname) {
if(isclick==true){
wx.request({
url: url + '/miniprogram/registeruser',
method: 'POST',
data: {
// unionid: unionid,
// token: token,
encryptedData: encryptedData,
iv: iv,
rawData: e.detail.rawData,
signature: e.detail.signature
//_token: sys_token
},
header: publicUrl.globalData.header,
success: function (res) {
console.log("注册用户成功==============")
console.log(res)
if (res.data.code == 0) {
isclick = false
console.log("code================0")
var laravelsession = res.header["Set-Cookie"].match(/laravel_session=(.*?);/)[1]
var xsrftoken = res.header["Set-Cookie"].match(/XSRF-TOKEN=(.*?);/)[1]
var sys_token = res.header["xxvv"]
publicUrl.globalData.laravelsession = laravelsession
publicUrl.globalData.xsrftoken = xsrftoken
publicUrl.globalData.sys_token = sys_token
var header = {
'Content-type': 'application/x-www-form-urlencoded',
'Cookie': 'XSRF-TOKEN=' + xsrftoken + '; ' + 'laravel_session=' + laravelsession,
'X-CSRF-TOKEN': sys_token,
'X-Requested-With': 'XMLHttpRequest',
'uf': '1'
}
publicUrl.globalData.header = header
that.setData({
userInfo: res.data.result
})
// userInfo = res.data.result
wx.setStorage({
key: "myuser",
data: res.data.result
})
publicUrl.globalData.userInfo = res.data.result
wx.setStorage({
key: "userInfo",
data: res.data.result
})
if (that.data.sid) {
if (that.data.share == 1) {
wx.reLaunch({
url: '/pages/ranking/ranking?storeid=' + that.data.sid + '&share=1'
})
} else {
wx.reLaunch({
url: '/pages/ranking/ranking?storeid=' + that.data.sid
})
}
} else if (that.data.uunionid) {
if (that.data.share == 1) {
wx.reLaunch({
url: '/pages/personal/personal?uunionid=' + that.data.uunionid + '&share=1'
})
} else {
wx.reLaunch({
url: '/pages/personal/personal?uunionid=' + that.data.uunionid
})
}
} else {
wx.reLaunch({
url: '/pages/city/city?source=login',
})
}
} else if (res.data.code == 5588) {
login(that)
} else {
console.log("code==============else=========", res.data.code)
}
},
fail: function (res) {
console.log("注册用户失败===============")
}
})
}
} else {
var userInfo = publicUrl.globalData.userInfo
var myuser = wx.getStorageSync('myuser');
if (that.data.sid) {
if (that.data.share == 1) {
wx.reLaunch({
url: '/pages/ranking/ranking?storeid=' + that.data.sid + '&share=1'
})
} else {
wx.reLaunch({
url: '/pages/ranking/ranking?storeid=' + that.data.sid
})
}
} else if (that.data.uunionid) {
if (that.data.share == 1) {
wx.reLaunch({
url: '/pages/personal/personal?uunionid=' + that.data.uunionid + '&share=1'
})
} else {
wx.reLaunch({
url: '/pages/personal/personal?uunionid=' + that.data.uunionid
})
}
} else {
wx.reLaunch({
url: '/pages/city/city?source=login',
})
}
}
} else {
console.log("您没有授权哦")
wx.showToast({
title: '您没有授权哦~',
icon: 'none',
duration: 2000
})
}
},
你自己写个事件节流。在getUserInfo绑定的事件里面。
根据取出的东西。如果取出来一遍之后。即使在点也不走接口
不太懂,,,,能说的详细点吗
bindGetUserInfo: function (e) {
console.log(e)
wx.showToast({
title: '点击了button',
icon: 'success',
duration: 2000
})
console.log("isclick=====bindGetUserInfo=======11111", isclick)
var that = this
console.log("userInfo===========")
console.log(that.data.userInfo)
// var token = userInfo.token
// var unionid = userInfo.user.unionid
var encryptedData = e.detail.encryptedData;
var iv = e.detail.iv;
var laravelsession = publicUrl.globalData.laravelsession;
var xsrftoken = publicUrl.globalData.xsrftoken;
var sys_token = publicUrl.globalData.sys_token;
if (e.detail.userInfo != undefined) {
console.log("isclick=======2222=", isclick)
if (!that.data.userInfo.user.nickname) {
if(isclick==true){
wx.request({
url: url + '/miniprogram/registeruser',
method: 'POST',
data: {
// unionid: unionid,
// token: token,
encryptedData: encryptedData,
iv: iv,
rawData: e.detail.rawData,
signature: e.detail.signature
//_token: sys_token
},
header: publicUrl.globalData.header,
success: function (res) {
console.log("注册用户成功==============")
console.log(res)
if (res.data.code == 0) {
isclick = false
console.log("code================0")
var laravelsession = res.header["Set-Cookie"].match(/laravel_session=(.*?);/)[1]
var xsrftoken = res.header["Set-Cookie"].match(/XSRF-TOKEN=(.*?);/)[1]
var sys_token = res.header["xxvv"]
publicUrl.globalData.laravelsession = laravelsession
publicUrl.globalData.xsrftoken = xsrftoken
publicUrl.globalData.sys_token = sys_token
var header = {
'Content-type': 'application/x-www-form-urlencoded',
'Cookie': 'XSRF-TOKEN=' + xsrftoken + '; ' + 'laravel_session=' + laravelsession,
'X-CSRF-TOKEN': sys_token,
'X-Requested-With': 'XMLHttpRequest',
'uf': '1'
}
publicUrl.globalData.header = header
that.setData({
userInfo: res.data.result
})
// userInfo = res.data.result
wx.setStorage({
key: "myuser",
data: res.data.result
})
publicUrl.globalData.userInfo = res.data.result
wx.setStorage({
key: "userInfo",
data: res.data.result
})
if (that.data.sid) {
if (that.data.share == 1) {
wx.reLaunch({
url: '/pages/ranking/ranking?storeid=' + that.data.sid + '&share=1'
})
} else {
wx.reLaunch({
url: '/pages/ranking/ranking?storeid=' + that.data.sid
})
}
} else if (that.data.uunionid) {
if (that.data.share == 1) {
wx.reLaunch({
url: '/pages/personal/personal?uunionid=' + that.data.uunionid + '&share=1'
})
} else {
wx.reLaunch({
url: '/pages/personal/personal?uunionid=' + that.data.uunionid
})
}
} else {
wx.reLaunch({
url: '/pages/city/city?source=login',
})
}
} else if (res.data.code == 5588) {
login(that)
} else {
console.log("code==============else=========", res.data.code)
}
},
fail: function (res) {
console.log("注册用户失败===============")
}
})
}
} else {
var userInfo = publicUrl.globalData.userInfo
var myuser = wx.getStorageSync('myuser');
if (that.data.sid) {
if (that.data.share == 1) {
wx.reLaunch({
url: '/pages/ranking/ranking?storeid=' + that.data.sid + '&share=1'
})
} else {
wx.reLaunch({
url: '/pages/ranking/ranking?storeid=' + that.data.sid
})
}
} else if (that.data.uunionid) {
if (that.data.share == 1) {
wx.reLaunch({
url: '/pages/personal/personal?uunionid=' + that.data.uunionid + '&share=1'
})
} else {
wx.reLaunch({
url: '/pages/personal/personal?uunionid=' + that.data.uunionid
})
}
} else {
wx.reLaunch({
url: '/pages/city/city?source=login',
})
}
}
} else {
console.log("您没有授权哦")
wx.showToast({
title: '您没有授权哦~',
icon: 'none',
duration: 2000
})
}
},
在
这个样子
感谢
不客气,给个赞同就好了