了解如何解决未捕获的SyntaxError:函数语句需要函数名称

我正在尝试创建一个通过Telegram进行身份验证的简单Web应用程序。 Telegram有自己的带有回调的小部件,该小部件具有登录后返回的用户数据的脚本。问题出在脚本属性“ data-onauth”中,此处您传递了要在成功进行身份验证后执行的回调。

https://core.telegram.org/widgets/login-小部件文档(如果需要)

要在您想要的位置找到登录按钮,您只需要粘贴Telegram的小部件生成器给出的脚本,但是由于我无法在组件模板中粘贴脚本标签(vue不会编译它,只会返回错误)我选择创建脚本元素,添加所需的属性并将其附加到mount()中。

这是我的组件代码

<template>
  <header>
      <div class="auth" id="telegramAuth">
      </div>
  </header>
</template>

<script>
export default {
  name: "Header",data: () => ({}),mounted() {
    let telegramAuth = document.createElement("script");
    telegramAuth.setattribute("async","");
    telegramAuth.setattribute(
      "src","https://telegram.org/js/telegram-widget.js?7"
    );

    telegramAuth.setattribute("data-userpic","false");
    telegramAuth.setattribute("data-telegram-login","t_adv_bot");
    telegramAuth.setattribute("data-size","large");
    telegramAuth.setattribute("data-onauth",this.loginWithTelegram);
    telegramAuth.setattribute("data-request-access","write");
    document.querySelector("#telegramAuth").appendChild(telegramAuth);
  },methods: {
    loginWithTelegram: function onTelegramAuth(user) {
        console.log(user);
    }
  }
};
</script>

但是当我尝试这样做时,我得到了Uncaught SyntaxError:函数语句需要一个函数名称。 而且我不知道如何解决。在此先感谢您,我的英语不好。

zkx993299184 回答:了解如何解决未捕获的SyntaxError:函数语句需要函数名称

  methods: {
    loginWithTelegram(user) {
     console.log(user);
    }
  }
本文链接:https://www.f2er.com/3155058.html

大家都在问