Nuxt.js: Using Facebook's javascript sdk with Nuxtjs

Created on 24 Oct 2017  路  10Comments  路  Source: nuxt/nuxt.js

I would like to use Facebook's comments plugin on some routes/paths of my website. I am using Vuejs and Nuxtjs for server-side rendering. I have gone through the Nuxtjs website to include plugins, but I couldn't find any help there. I have gone through these (1, 2) SO questions as well, but they didn't help me either. Could you please guide me how to use Facebook's SDK when using Nuxtjs I will be very much grateful.

This question is available on Nuxt.js community (#c1736)
help-wanted

Most helpful comment

I don't know whether it is a proper solution or not and i am new in Nuxtjs, you can correct me if i'm mistaken.
What i do is include the script _https://connect.facebook.net/en_US/all.js_ in nuxt config and create a js file in plugins folder, like below

image

and initialize the SDK with this.$initFbSDK() in mounted hook when have any page need to use the FB plugin.

All 10 comments

I have the same problem

i am using nuxt with spa mode , dont have any issue
image

@hanjeahwan Could you share your code how you configured fb jdk with nuxt?

I don't know whether it is a proper solution or not and i am new in Nuxtjs, you can correct me if i'm mistaken.
What i do is include the script _https://connect.facebook.net/en_US/all.js_ in nuxt config and create a js file in plugins folder, like below

image

and initialize the SDK with this.$initFbSDK() in mounted hook when have any page need to use the FB plugin.

@hanjeahwan excellent this is exactly what I was looking for

Does that solution load the facebook SDK always or only when it's needed? Here is a solution that loads it on demand only when needed (e.g. when the user looks at that specific page that uses it, and also assumes your module-loading/code-splitting is correct). My apologies though, the example is for the Stripe SDK.

https://github.com/webpack/webpack/issues/150#issuecomment-275952354

Whenever I try to create that plugin like the one mentioned here, I keep getting the message 'FB' is not defined from ESLint.

@samirph In your .js file, you can add /*global FB*/ at the top. Or simply call it window.FB as opposed to FB

Closing this issue as there's been no updates over 90 days.

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jaredreich picture jaredreich  路  3Comments

pehbehbeh picture pehbehbeh  路  3Comments

uptownhr picture uptownhr  路  3Comments

vadimsg picture vadimsg  路  3Comments

maicong picture maicong  路  3Comments