我尝试在 Quasar Framework 上使用https://github.com/phanan/vue-facebook-signin-button组件,我已经使用 npm 安装了它:
npm i vue-facebook-signin-button --save
我穿上了main.js
:
import FBSignInButton from 'vue-facebook-signin-button'
Vue.use( FBSignInButton ) // use facebook signin button
然后我添加了主.vue
文件:
<template>
<q-layout>
<div class="layout-view">
<fb-signin-button
:params="fbSignInParams"
@success="onFbSignInSuccess"
@error="onFbSignInError">
Sign in with Facebook
</fb-signin-button>
</div>
</q-layout>
</template>
<script>
// Facebook
var FB;
window.fbAsyncInit = function() {
FB.init( {
appId: process.env.FB_APPID,
cookie: true, // enable cookies to allow the server to access the session
xfbml: true, // parse social plugins on this page
version: 'v2.8' // use graph api version 2.8
} )
}
(function( d, s, id ) {
var js, fjs = d.getElementsByTagName( s )[ 0 ];
if( d.getElementById( id ) ) return;
js = d.createElement( s );
js.id = id;
js.src = "//connect.facebook.net/en_US/sdk.js";
fjs.parentNode.insertBefore( js, fjs );
}( document, 'script', 'facebook-jssdk' ))
export default {
store,
data () {
return {
fbSignInParams: {
scope: '',
return_scopes: true
}
}
},
computed: {},
methods: {
onFbSignInSuccess ( response ) {
console.log( 'res', response )
FB.api( '/me', dude => {
console.log( 'dude', dude )
console.log( `Good to see you, ${dude.name}.` )
} )
},
onFbSignInError ( error ) {
console.log( 'OH NOES', error )
}
}
}
</script>
但它给出了一个运行时错误:
(unknown) [Vue warn]: Unknown custom element: <fb-signin-button> - did you register the component correctly? For recursive components, make sure to provide the "name" option.
found in
---> <Index> at /home/asd/SPA/src/components/Index.vue
<App> at /home/asd/SPA/src/App.vue
<Root>
还有另一个错误fbAsyncInit
:
sdk.js:96 Uncaught TypeError: Cannot read property 'init' of undefined
at window.fbAsyncInit (eval at <anonymous> (0.6374f77….js:243), <anonymous>:10:5)
at v.__wrapper (sdk.js:96)
at sdk.js:140