zhuce: function () {
let that = this;
if (that.data.username.length == 0 || that.data.password.length == 0 || that.data.password == "" || that.data.password == "") {
wx.showModal({
title: '賬號或密碼不能為空!',
})
} else if (that.data.username.length < 10) {
wx.showModal({
title: '賬號格式不正確!',
})
} else if (that.data.password.length < 6) {
wx.showModal({
title: '密碼位數不能少于6位!',
})
} else {
console.log("Hello,用戶:" + this.data.username + "\npassword:" + this.data.password);
wx.request({
url: 'http://localhost:8088/demo/User/ListByStuNo',
method: 'GET',
header: {
'content-type': 'application/x-www-form-urlencoded'
},
data: {
'stuNo': this.data.username,
},
success: function (res) {
console.log("回呼函式:" + res.data);
var ResData = res.data;
if (ResData == true) {
wx.showModal({
title: '用戶已存在!',
duration: 2000
})
} else {
wx.request({
url: 'http://localhost:8088/demo/User/register',
method: 'POST',
header: {
'content-type': 'application/x-www-form-urlencoded'
},
data: {
'stuNo': that.data.username,
'passWord': that.data.password
},
success: function (res) {
console.log("回呼函式:" + res.data);
var ResData = res.data;
if (ResData == true) {
wx.showModal({
title: '注冊成功!',
duration: 2000
})
wx.redirectTo({
url: '../denglu/denglu',
})
} else {
wx.showModal({
title: '注冊失敗!',
duration: 2000
})
}
}
})
}
}
})
}
},
這是一個注冊模塊,判斷用戶是否存在回傳一個回呼函式,在回呼函式的判斷中繼續進行注冊,但是卻出現了回呼函式無法對page頁里面的data進行呼叫的問題,大家都在說這個success是一個閉包,this的指向不同,提前賦給that也不管用,請問前輩們這個應該怎么解決。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/277551.html
標籤:微信開發
上一篇:【Android專案實戰 | 從零開始寫app (六) 】用TabLayout+ViewPager搭建App 框架主頁面底部導航欄
