微信小程序之方法调用报错(TypeError: Cannot read property ‘RegisterStatues‘ of undefined)

出现错误: TypeError: Cannot read property 'RegisterStatues' of undefined,实际无法调用其他方法和变量,如:在handleRegister函数中无法调用RegisterStatues函数。

原因: 因为在success回调函数中,this指向的不再是Vue实例,而是success函数本身。因此,您需要在success函数外部保留正确的上下文,可以使用变量that 或者ES6的箭头函数 来解决这个问题。

修改后:

过在success函数中使用that来调用RegisterStatues函数

javascript 复制代码
RegisterStatues: function() {
    var that = this; // 保存正确的上下文
    // 其余代码不变
},

handleRegister: function(e) {
    const that = this; // 保存正确的上下文
    // 其余代码不变

    wx.request({
        // 取消成功要更新报名状态
        success: function(res) {
            if (res.statusCode === 200) {
                wx.showToast({
                    title: '取消报名成功',
                    icon: 'success',
                    duration: 2000
                });
                // 使用that来调用RegisterStatues函数
                that.RegisterStatues();
            } else {
                wx.showToast({
                    title: '没找到报名信息',
                    icon: 'success',
                    duration: 2000
                });
            }
        },
        // 其他代码不变
    });
}
相关推荐
计算机毕设指导631 分钟前
基于微信小程序的个性化漫画阅读推荐系统【源码文末联系】
java·python·微信小程序·小程序·tomcat·maven·intellij-idea
百锦再32 分钟前
开发抖音小程序组件大全概述
人工智能·python·ai·小程序·aigc·notepad++·自然语言
Lucky小黄人13 小时前
微信小程序开发常见报错
微信小程序·小程序
Stanford_11061 天前
【2026新年启程】学习之路,探索之路,技术之路,成长之路……都与你同行!!!
前端·c++·学习·微信小程序·排序算法·微信开放平台
初学者52131 天前
微信小程序调用录音没反应,本地开发测试却没问题,operateRecorderfail appid privacy api banned
微信小程序·小程序
微爱帮监所写信寄信1 天前
微爱帮监狱寄信写信小程序信件内容实时保存技术方案
java·服务器·开发语言·前端·小程序
说私域1 天前
基于开源AI大模型AI智能名片S2B2C商城小程序的内容价值生成与多点选择传播策略研究
人工智能·微信·小程序·开源
2501_916007472 天前
iPhone APP 性能测试怎么做,除了Instruments还有什么工具?
android·ios·小程序·https·uni-app·iphone·webview
2501_915106322 天前
Windows 环境下有哪些可用的 iOS 上架工具, iOS 上架工具的使用方式
android·ios·小程序·https·uni-app·iphone·webview
2501_915106322 天前
iOS 抓包工具有哪些?不同类型的抓包工具可以做什么
android·ios·小程序·https·uni-app·iphone·webview