首页 > 解决方案 > ReferenceError:(函数)未定义

问题描述

我试图在成功的承诺上显示弹出通知,但我不断收到“ReferenceError:doNotification 未定义”。如果我在我的 html 中单击按钮时触发 doNotification,它会起作用。我的电子邮件功能也可以正常工作,因为 console.log 将适当的参数打印到控制台。我不确定为什么从我的电子邮件功能中调用 doNotification 时会收到此错误?

export default {
  methods: {

    sendEmail: (e) => {
      emailjs.sendForm('gmail', 'template', e.target, 'user')
        .then((result) => {
            console.log('SUCCESS!', result.status, result.text);
            doNotification();
        }, (error) => {
            console.log('FAILED...', error);
        });
    e.target.reset();
    },

    doNotification() {
      this.$toast.success("Your message has been sent!", {
      position: "bottom-right"});
    }}}

标签: javascriptfunctionvue.jsreferenceerror

解决方案


您缺少此绑定。更改doNotification()this.doNotification()


推荐阅读