简体   繁体   English

Vue.js Facebook 登录

[英]Vue.js Facebook Login

I'm implementing a Facebook Login module which I have already imported and it works, but the trouble comes when I want to bind the response to an input.我正在实现一个我已经导入的 Facebook 登录模块并且它可以工作,但是当我想将响应绑定到输入时问题就来了。 How could I achieve it?我怎样才能实现它? I'm kinda new with Vue.js我对 Vue.js 有点陌生

I'm using this component我正在使用这个组件

FbLogin.vue FbLogin.vue

 <template>
  <fb-signin-button
    :params="fbSignInParams"
    @success="onSignInSuccess"
    @error="onSignInError">
    Ingresa con FB
  </fb-signin-button>
</template>

<script>
export default {
  data () {
    return {
      fbSignInParams: {
        scope: 'email,user_likes',
        return_scopes: true,
      },
    }
  },
  methods: {
    onSignInSuccess (response) {
      FB.api('/me', dude => {
      console.log(`Good to see you, ${dude.name}.`)
      })
    },
    onSignInError (error) {
      console.log('Error de fBlogin', error)
    },
  }
}
</script>

Form.vue表单.vue

<template lang="pug">
  .field
    pm-fb
    label.label
      h1.sutitle
      .control
        input.input.is-hovered(type="text" v-model="username" placeholder="Nombre(s)") 
        input.input.is-hovered(type="text" placeholder="Apellido Paterno")
</template>

<script>
import PmFb from '@/components/fBLogin.vue'
export default {
  components: {
    PmFb
  }
}
</script>

It displays the info in the console and that's what I want to bind to the input.它在控制台中显示信息,这就是我要绑定到输入的内容。

You could use string interpolation in Vue templates to display that message.您可以在 Vue 模板中使用字符串插值来显示该消息。

First, add a data property (eg, named "message"):首先,添加一个data属性(例如,命名为“消息”):

export default {
  data() {
    return {
      message: ''
    };
  }
}

Then, add the message in your template, surrounded by curly brackets:然后,在模板中添加message ,用大括号括起来:

<template>
  <div>{{message}}</div>
</template>

When your Facebook login result is determined, set this.message to the desired message, similar to this:确定您的 Facebook 登录结果后,将this.message设置为所需的消息,类似于:

methods: {
  onSignInSuccess (response) {
    FB.api('/me', dude => {
      this.message = `Good to see you, ${dude.name}.`
    })
  },
  onSignInError (error) {
    this.message = `Error de fBlogin: ${error}`
  },
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM