Facebook JS SDK和Pug:如何包含脚本代码?

问题描述 投票:0回答:1

我正在尝试使用FB sdk。它要求代码在html的脚本标签中使用。我正在使用Pug而不是纯HTML,并且格式不正确。

这是我当前的哈巴狗文件,也是我尝试使其正常工作的最新尝试。 此迭代中没有脚本标签,但是我已经在脚本标签中进行了尝试,并且没有差异。

我认为它必须在脚本中,因为它是客户端代码。

layout.pug

doctype html
html
  head
  body
    //works - just testing
    - const x = 1
    //works - just testing
    - function test(){console.log('test')}
    //error - not a real error. Seems like syntax
    // Content Security Policy: The page’s settings blocked the loading of a resource at http://localhost:3000/favicon.ico
    - function testWrapper(){
        window.fbAsyncInit = function() {
          FB.init({
            appId            : '1111111',
            autoLogAppEvents : true,
            xfbml            : true,
            version          : 'v4.0' 
          });
        }
      }
    - testWrapper()
  // not sure if this is working, but I don't think so.
 script(async defer src="https://connect.facebook.net/en_US/sdk.js")

我该如何使用它?这是layout.pug,所以我不确定如何渲染模板时传递JS,否则我只是这样做。

javascript node.js pug facebook-javascript-sdk
1个回答
0
投票

[我想我从2小时前尝试了第一次解决方案就解决了。那时它不起作用,但是间距必须已经关闭并抛出错误。现在,我得到了200个FB SDK,因此它必须可以正常工作。

我认为这样的帕格中包含SDK代码:

script. 
      window.fbAsyncInit = function() {
        FB.init({
          appId            : '111111',
          autoLogAppEvents : true,
          xfbml            : true,
          version          : 'v5.0'
        });
      };
 script(async defer src="https://connect.facebook.net/en_US/sdk.js")
© www.soinside.com 2019 - 2024. All rights reserved.