错误样例: e.showError is not a function. (In ‘e.showError(a.data.message)’, ‘e.showError’ is undefined)
问题出在this.showError函数,这个wx.request是复制其它页面过来的,其中自定义showError函数没有随着一起复制过来,所以会报错。
checkMoney: function(){
//检测money是否>0,如果>0则跳转到花费活动页面。
wx.request({
url: app.globalData.host + ‘user/info/get’,
data: {
token: app.globalData.token
},
header: {
‘content-type’: ‘application/json’
},
method: ‘POST’,
dataType: ‘json’,
responseType: ‘text’,
success: (result) => {
if (result.data.code == 200) {
this.setData({
money: result.data.user_info.money
})
if(this.data.money>0){
if(app.globalData.getmoney == true){
wx.navigateTo({
url: ‘/pages/phonecash/phonecash’,
})
app.globalData.getmoney = false
console.log(app.globalData.getmoney)
}
}
} else {
this.showError(result.data.message);
}
},
fail: () => {
this.showError(“网络错误”);
},
complete: () => {} });
现在对此进行修改,首先是添加ShowError函数:
showError(msg) {
wx.showToast({
title: msg,
icon: ‘none’,
duration: 1500,
mask: false
});
},
然后更改checkMoney的触发条件,让有token的用户才能触发:
if(app.globalData.token!=’’) this.checkMoney();