【问题标题】:vue 2 [GSI_LOGGER]: The value of 'callback' is not a function. Configuration ignoredvue 2 [GSI_LOGGER]: 'callback' 的值不是一个函数。配置被忽略
【发布时间】:2021-12-22 17:42:23
【问题描述】:

我正在尝试在我的 Vue2 项目中添加一个 google 登录按钮,因此我尝试按照此处的说明进行操作 https://developers.google.com/identity/gsi/web/guides/display-button#html

所以我把下面这段代码放到我的Hello.vue 组件中

<template>
  <section>
      <div id="g_id_onload"
         data-client_id="YOUR_GOOGLE_CLIENT_ID"
         data-callback=myCallbackFunction
         data-auto_prompt="false">
      </div>
      <div class="g_id_signin"
         data-type="standard"
         data-size="large"
         data-theme="outline"
         data-text="sign_in_with"
         data-shape="rectangular"
         data-logo_alignment="left">
      </div>
  </section>
</template>
<script>
  export default {      
    methods: {
      myCallbackFunction(){
      }
    }
  }
</script>

当我重新加载页面/组件时,它会显示错误[GSI_LOGGER]: The value of 'callback' is not a function. Configuration ignored.

我认为问题在于data-callback 无法找到或识别我已经在methods 下声明的myCallbackFunction。我也尝试将myCallbackFunction 放在computed 下,但它仍然返回相同的错误。那么有什么方法可以让我完成这项工作吗?

【问题讨论】:

  • 尝试将myCallbackFunction 放在引号中:data-callback="myCallbackFunction"。它显示在此属性的doc's example 中。让我知道它是否有效。
  • @FaridShumbar 很抱歉后来的回复。我试过了,但它仍然返回相同的错误

标签: vue.js google-identity


【解决方案1】:

好的,我想我明白了——但我从使用 HTML 文档切换到了 JavaScript 文档,因为 VueJS 在这方面效果更好。

不过,我不知道挂载是否是 最佳 选项,但它至少可以按预期工作。

只需使用方法创建的回调函数即可。

  mounted: function () {
   google.accounts.id.initialize({
   client_id:
    'xxxxxxx.apps.googleusercontent.com',
     callback: this.handleCredentialResponse,
  })
  google.accounts.id.prompt()}

【讨论】:

    猜你喜欢
    • 2022-11-17
    • 2021-07-04
    • 2016-09-13
    • 1970-01-01
    • 1970-01-01
    • 2019-02-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多