Skip to content

Instantly share code, notes, and snippets.

@artrayd
Forked from wdmtech/index.js
Created September 23, 2020 21:05
Show Gist options
  • Save artrayd/d0bf6b4a173b4683dc42b4df90cbc469 to your computer and use it in GitHub Desktop.
Save artrayd/d0bf6b4a173b4683dc42b4df90cbc469 to your computer and use it in GitHub Desktop.
Facebook SDK (Graph/REST API) integration as a Vue.js mixin
export let facebookSDK = {
mounted () {
let _this = this
this.$nextTick(() => {
window.fbAsyncInit = function () {
FB.init({
appId: 'XXX',
xfbml: true,
version: 'v2.6'
})
FB.AppEvents.logPageView()
_this.FB = FB
console.log('FB SDK was initialized as mixin')
};
(function (d, s, id) {
let 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'))
})
},
data () {
return {
FB: {}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment