Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
260 views
in Technique[技术] by (71.8m points)

Use Facebook SDK with Nuxt.js

I'm trying to use Facebook SDK with nuxt.js referring this post post link. But It's says window.FB is undefined.

How can i slove tis issue or is any other way to use facebook sdk in nuxt.js?

fb-sdk.js

window.fbAsyncInit = function() {
    FB.init({
      appId      : '############',
      cookie     : true,
      xfbml      : true,
      version    : 'v9.0'
    });
      
    FB.AppEvents.logPageView();       
  };

  (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 = "https://connect.facebook.net/en_US/sdk.js";
     fjs.parentNode.insertBefore(js, fjs);
   }(document, 'script', 'facebook-jssdk'));


method

fbLog() 
{
      window.FB.getLoginStatus(function (response) {
        this.statusChangeCallback(response)
      })
    },
    statusChangeCallback(response) {
      console.log(response)
 },

nuxt.xonfig.js

head: {
    titleTemplate: '%s - test',
    title: 'test',
    meta: [
      { charset: 'utf-8' },
      { name: 'viewport', content: 'width=device-width, initial-scale=1' },
      { hid: 'description', name: 'description', content: '' },
    ],
    link: [{ rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }],
    script: [
      { src: 'js/fb-sdk.js' }
     ],
  },
question from:https://stackoverflow.com/questions/65560007/use-facebook-sdk-with-nuxt-js

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Solve the problem, Problem is I'm trying it on Firefox and the Firefox tracking option disable that script after turn off it works as expected.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...