如何在不同的 vue 方法中的函数内调用 vue 方法

克里斯托弗·马尔·埃纳尔松

我试图在另一个名为 testing 的 vue 方法内的函数中调用名为“updateUserToPremium()”的 Vue 方法。我正在尝试这样做,因为“rp”是一个由支付提供商提供的 javascript 事件处理程序。

我也试过 'this.updateUserToPremium(userId)' 但这并不能解决问题。我试图了解范围之间的关系,但我错过了一些东西。

methods: {
  updateUserToPremium(userId) {
    axios.post(`/user/${userId}`, {}, {
      headers: { "Authorization": `Bearer ${this.$store.state.token}` }
    }).then(res => {
        console.log('Success session creation');
        this.routeToStartpage()
    }).catch(error => {
        console.log(error);
        return error;
    })
  },

  testing(userId) {
    var rp = new Reepay.ModalSubscription(sessionId);
    rp.addEventHandler(Reepay.Event.Accept, function(data) {
        console.log('Success', data);

        updateUserToPremium(userId);  // <--- This triggers updateUserToPremium is not defined' 
    
        rp.destroy();
    })
  },
}
由 Alnughnugh 发表

尝试这样的调用方法:

rp.addEventHandler(Reepay.Event.Accept, (data) => {
    console.log('Success', data);

    this.updateUserToPremium(userId);  // <--- This triggers updateUserToPremium is not defined' 

    rp.destroy();
})

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章