源代码为:
const app = getApp()
wx.cloud.init({
env: 'houseworkapp-1g2njf66a3441491'
})
const db = wx.cloud.database({
env: 'houseworkapp-1g2njf66a3441491'
})
Page({
data: {
phone: '',
username: '',
usernameverify:1,
NewChanges: '',
NewChangesAgain: '',
},
handleInputPhone: function (e) {
var that = this;
that.setData({
phone: e.detail.value
})
},
handleusername: function (e) {
var that = this;
this.setData({
username: e.detail.value
})
},
handleNewChanges: function (e) {
var that = this;
that.setData({
NewChanges: e.detail.value
})
},
handleNewChangesAgain: function (e) {
var that = this;
that.setData({
NewChangesAgain: e.detail.value
})
},
submit: function (e) {
var that = this
db.collection('users'[相应的数据表]).where({ username: that.data.username }).get({
success: function (res) {
var that = this
that.setData({
usernameverify: res.data[0].verifycode
})
}
})
if (that.data.phone == '') {
console.log('a')
wx.showToast({
title: '手机号码不能为空',
duration: 2000
})
} else if (that.data.phone.trim().length != 11) {
console.log('b')
wx.showToast({
title: '手机号码格式不对',
duration: 2000
})
} else if (that.data.username == '') {
console.log('c')
wx.showToast({
title: '登录名不能为空',
duration: 2000
})
}
else if (!that.data.usernameverify) {
console.log('d')
wx.showToast({
title: '登录名已经被注册了',
duration: 2000
})
}
else if (that.data.NewChanges == '') {
console.log('e')
wx.showToast({
title: '请输入密码',
duration: 2000
})
return
} else if (that.data.NewChangesAgain != that.data.NewChanges) {
console.log('f')
wx.showToast({
title: '两次密码不一致',
duration: 2000
})
return
} else {
var that = this
db.collection('users').add({
data: {
username: that.data.username,
password: that.data.NewChanges,
phonenum: that.data.phone,
verifycode: 1
},
success: function (res) {
}
})
}
}
})
第47行报错